如何标准化直方图
我有这个直方图,它对等对数间隔的容器中的数组“d”进行计数。
max_val=np.log10(max(d))
min_val=np.log10(min(d))
logspace = np.logspace(min_val, max_val, 50)
hist(d,bins=logspace,label='z='+str(redshift),histtype='step')
show()
问题是我希望将其标准化,以便面积为一。使用选项 Normed=True 我没有得到结果,这可能是因为我使用的是对数箱。因此我尝试用这种方式标准化直方图:
H=hist(d,bins=logspace,label='z='+str(redshift),histtype='step')
H_norm=H[0]/my_norm_constant
但是我不知道如何绘制 H_norm 与 bin 的关系图
I have this histogram which counts the array "d" in equally log-spaced bins.
max_val=np.log10(max(d))
min_val=np.log10(min(d))
logspace = np.logspace(min_val, max_val, 50)
hist(d,bins=logspace,label='z='+str(redshift),histtype='step')
show()
The problem is that I want it to be normalized so as the area is one. Using the option Normed=True I didn't get the result, it might be due to fact that I'm using logarithmic bins. Therefore I tried normalizing the histogram in this way:
H=hist(d,bins=logspace,label='z='+str(redshift),histtype='step')
H_norm=H[0]/my_norm_constant
But then I don't know how to plot H_norm versus the bins
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我尝试了normed=True,面积为1:
您可以运行代码并检查输出吗?如果不是 1,请检查您的 numpy 版本。运行代码时收到此警告消息:
C:\Python26\lib\site-packages\matplotlib\axes.py:7680: UserWarning:
此版本修复了 NumPy 直方图中的标准化错误
1.5版本之前的函数,出现不一致
箱宽度。返回和绘制的值现在是密度:
n / (N * bin 宽度),
其中 n 是 bin 计数,N 是点总数。
自己绘制图表:
I tried normed=True, and the area is 1:
can you run the code, and check the output. If it is not 1, check your numpy version. I got this warning message when run the code:
C:\Python26\lib\site-packages\matplotlib\axes.py:7680: UserWarning:
This release fixes a normalization bug in the NumPy histogram
function prior to version 1.5, occuring with non-uniform
bin widths. The returned and plotted value is now a density:
n / (N * bin width),
where n is the bin count and N the total number of points.
to plot the graph yourself:
这使用常见的归一化,将 bin 高度归一化为 1,无论 bin 宽度如何。
生成的直方图:
This uses the common normalization which normalizes bin height to add up to 1 irrespective of bin width.
resulting histogram plot: