询问在python中绘制1D数组直方图的方法
连续剧:连续剧询问在python中绘制1D数组直方图的方法,python,pandas,series,Python,Pandas,Series,连续剧:连续剧 0 111.8040373 2 140.10805914 4 117.64930612 5 111.85077526 6 137.22535711 7 138.59732811 ... 123 103.63270617 你能为我提供绘制系列(如熊猫)直方图的建议吗?我还希望使用范围[0150]内的箱子宽度(例如5)。我找到了一个脚本,但尝试了一下,却无法运行。这是我个人用来制作直方图的脚本 import numpy as np import pylab as P
0 111.8040373
2 140.10805914
4 117.64930612
5 111.85077526
6 137.22535711
7 138.59732811
...
123 103.63270617
你能为我提供绘制系列(如熊猫)直方图的建议吗?我还希望使用范围
[0150]
内的箱子宽度(例如5)。我找到了一个脚本,但尝试了一下,却无法运行。这是我个人用来制作直方图的脚本
import numpy as np
import pylab as P
def binner(LB, UB, step=1):
N = int((UB-LB+1)/float(step) + 1)
return [LB + step * (i - 1/float(2)) for i in xrange(N)]
def f_hist(x, bins=None, param=20, h_type='bar', barwidth=0.8,filename=None):
P.figure()
if bins is None:
if hasattr(param, "__iter__"):
if len(param) == 2:
LB, UB = param
step = 1
elif len(param) == 3:
LB, UB, step = param
else:
raise Exception
bins = binner(LB, UB, step)
n, bins, patches = P.hist(x,bins,histtype=h_type,rwidth=barwidth)
else:
n, bins, patches = P.hist(x,param,histtype=h_type,rwidth=barwidth)
else:
n, bins, patches = P.hist(x, bins, histtype=h_type, rwidth=barwidth)
if filename is None:
P.show()
else:
P.savefig(filename)
print "Histogram saved as {}".format(filename)
return filename
if __name__ == '__main__':
mu, sigma = 200, 25
LB, UB, step = 100, 300, 10
x = mu + sigma*P.randn(10000)
f_hist(x, param = (LB, UB, step))
f_hist(x)
您可以看到正态分布的示例案例 我不知道你用两个变量的直方图是什么意思。你期望它是什么样子?@cdhagmann对模糊的表达式表示抱歉。例如,我将分别计算区间(0,5)、(5,10)、(145150)中的数据数量。但是我们是在看
0,2,4。。。123
还是在111.8040373…
系列?还是你希望做两件事?我们只考虑第二列,第一个包括标签。是的,你说得对!他可能会工作。按照你的建议,我已经尝试了hist(series,bins=30,range=[0150])。figure
它是有效的,但是,当我尝试series.hist(bins=30,range=[0150])
时,这个数字没有出来。这个步骤不应该是5吗?