How can I create a histogram that shows the probability distribution given by an array of numbers x from 0-1? I expect each bar to be <= 1 and that if I sum the y values ββof each bar, they should add up to 1.
For example, if x = [.2, .2, .8], then I expect a graph showing 2 bars, one at .2 with a height of .66, one at 0.8 with a height of .33.
I tried:
matplotlib.pyplot.hist(x, bins=50, normed=True)
which gives me a histogram with bars that go above 1. I am not saying what is wrong, as this is what the normal parameter will do according to the documentation, but it does not show the probability.
I also tried:
counts, bins = numpy.histogram(x, bins=50, density=True) bins = bins[:-1] + (bins[1] - bins[0])/2 matplotlib.pyplot.bar(bins, counts, 1.0/50)
which also gives bars whose y values ββadd up to more than 1.
source share