pylab.hist(data, normed=1). Normalization seems to work incorrect


Question

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?

enter image description here

1
41
3/31/2011 12:51:37 PM

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

47
5/23/2017 12:17:54 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon