相关疑难解决方法(0)

如何在Python中将bin系列浮点值转换为直方图?

我在float中设置了值(总是小于0).我希望将其分为直方图,即e.直方图中的每个条形包含值范围[0,0.150)

我的数据看起来像这样:

0.000
0.005
0.124
0.000
0.004
0.000
0.111
0.112
Run Code Online (Sandbox Code Playgroud)

我的代码如下,我希望得到的结果看起来像

[0, 0.005) 5
[0.005, 0.011) 0
...etc.. 
Run Code Online (Sandbox Code Playgroud)

我尝试用我的这个代码做这样的binning.但它似乎没有用.什么是正确的方法呢?

#! /usr/bin/env python


import fileinput, math

log2 = math.log(2)

def getBin(x):
    return int(math.log(x+1)/log2)

diffCounts = [0] * 5

for line in fileinput.input():
    words = line.split()
    diff = float(words[0]) * 1000;

    diffCounts[ str(getBin(diff)) ] += 1

maxdiff = [i for i, c in enumerate(diffCounts) if c > 0][-1]
print maxdiff
maxBin = max(maxdiff)


for i in range(maxBin+1):
     lo = 2**i - 1 …
Run Code Online (Sandbox Code Playgroud)

python statistics histogram binning

10
推荐指数
1
解决办法
2万
查看次数

如何使用python中内置函数的numpy或matplotlib正确生成3d直方图?

这更多是关于在 python 中创建 3d 直方图的一般问题。

我尝试在以下代码中使用 X 和 Y 数组创建 3d 直方图

import matplotlib
import pylab
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
from matplotlib import cm

def threedhist():
    X = [1, 3, 5, 8, 6, 7, 1, 2, 4, 5]
    Y = [3, 4, 3, 6, 5, 3, 1, 2, 3, 8]
    fig = pylab.figure()
    ax = Axes3D(fig)
    ax.hist([X, Y], bins=10, range=[[0, 10], [0, 10]])
    plt.xlabel('X')
    plt.ylabel('Y')
    plt.zlabel('Frequency')
    plt.title('Histogram')
    plt.show()
Run Code Online (Sandbox Code Playgroud)

但是,我收到以下错误

Traceback (most recent …
Run Code Online (Sandbox Code Playgroud)

python 3d numpy matplotlib histogram

7
推荐指数
2
解决办法
2万
查看次数

如何使用matplotlib中的直方图输出绘制散点图?

我想绘制一个类似于此的散点图:

在此处输入图片说明

我可以从数据中绘制直方图,但我希望对同一数据进行散点图绘制。有什么方法可以将hist()方法的输出用作散点图的输入吗?还是使用matplotlib中的hist()方法绘制散点图?该代码用于绘制直方图如下:

data = get_data()
plt.figure(figsize=(7,4))
ax = plt.subplots()
plt.hist(data,histtype='bar',bins = 100,log=True)
plt.show()
Run Code Online (Sandbox Code Playgroud)

python matplotlib scatter-plot

5
推荐指数
1
解决办法
5454
查看次数

使用Python的2D直方图

我正在尝试使用这些代码在Python中绘制2D直方图

from math import *
import pylab as p
import matplotlib.pyplot as plt
import numpy as np

x=part.points[:,0]
y=part.points[:,1]
z=part.points[:,2]

H, xedges, yedges = np.histogram2d(x, y, bins=(128,128))
H.shape, xedges.shape, yedges.shape

extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]

plt.imshow(H, extent=extent, interpolation='nearest')

plt.colorbar()
plt.xlabel("x")
plt.ylabel("y")
plt.show()
Run Code Online (Sandbox Code Playgroud)

一切都运行正常:我有一个颜色条,代表每个单元格中的计数.问题是我想得到计数的日志,但函数histrogram2d没有任何选项.

python 2d matplotlib histogram

3
推荐指数
1
解决办法
1万
查看次数

构建直方图

我正在尝试通过python制作直方图.我从以下代码段开始:

def histogram(L):
    d = {}
    for x in L:
        if x in d:
            d[x] += 1
        else:
            d[x] = 1
    return d
Run Code Online (Sandbox Code Playgroud)

我理解它使用字典功能来解决问题.但我对第4行感到困惑:if x in d:

d是要构造的,还没有什么,所以如果x在d中怎么样?

python histogram

1
推荐指数
1
解决办法
4038
查看次数

在 python 中使用 matplotlib 绘制直方图

我有一个包含 2 列的文件,例如:

111, 3  
122, 4  
155, 3  
192, 5  
11,  9  
123, 10  
120, 23
Run Code Online (Sandbox Code Playgroud)

我怎样才能编写类似 ((111,122,155,192,11,123,120),(3,4,3,5,9,10,23)) 的数据。现在我想做的就是使用将其绘制在直方图中matplotlib
请帮忙提供一些基本想法。!

python matplotlib histogram

0
推荐指数
1
解决办法
3437
查看次数

标签 统计

python ×6

histogram ×5

matplotlib ×4

2d ×1

3d ×1

binning ×1

numpy ×1

scatter-plot ×1

statistics ×1