本文介绍了pylab.hist(data,normed = 1)。标准化似乎工作不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用参数创建一个直方图,例如:



<$ p $



p> import pylab

data =([1,1,2,3,3,3,3,3,4,5.1])$ ​​b $ b pylab.hist (data,normed = 1)
pylab.show()

的箱子是1.但相反,其中一个箱子大于1.这个标准化做了什么?以及如何创建一个直方图与这样的归一化,直方图的积分将是相等的1?



解决方案

的直方图中的所有元素都等于1:
https://stackoverflow.com/a/16399202/1542814



复制&粘贴:

 权重= np.ones_like(myarray)/ float(len(myarray))
plt.hist myarray,weights =权重)

其中myarray包含您的数据

I'm trying to create a histogram with argument normed=1

For instance:

import pylab

data = ([1,1,2,3,3,3,3,3,4,5.1])    
pylab.hist(data, normed=1)
pylab.show()

I expected that the sum of the bins would be 1. But instead, one of the bin is bigger then 1. What this normalization did? And how to create a histogram with such normalization that the integral of the histogram would be equal 1?

解决方案

See my other post for how to make the sum of all bins in a histogram equal to one:https://stackoverflow.com/a/16399202/1542814

Copy & Paste:

weights = np.ones_like(myarray)/float(len(myarray))
plt.hist(myarray, weights=weights)

where myarray contains your data

这篇关于pylab.hist(data,normed = 1)。标准化似乎工作不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:21
查看更多