Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 370
smirnoffs Avatar asked Mar 31 '11 09:03

smirnoffs


1 Answers

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

like image 53
Carsten König Avatar answered Sep 28 '22 18:09

Carsten König