The following code sequentially creates histograms with empty cells, even if the number of samples is large. Empty bins seem to have a regular spacing, but have the same width as other regular baskets. This is obviously wrong - why is this happening? It seems that either the rvs method is not random, or the bin binning procedure is running. In addition, try changing the number of boxes to 50, and another oddity will appear. In this case, it seems that every other bean has a too high score associated with it.
""" An example of how to plot histograms using matplotlib
This example samples from a Poisson distribution, plots the histogram
and overlays the Gaussian with the same mean and standard deviation
"""
from scipy.stats import poisson
from scipy.stats import norm
from matplotlib import pyplot as plt
EV = 100
bins = 100
n = 10000
RV = poisson(EV)
samples = RV.rvs(n)
events, edges, patches = plt.hist(samples, bins, normed = True, histtype = 'stepfilled')
print events
mean = RV.mean()
sd = RV.std()
print "Mean is:", mean, " SD is: ", sd
Y = norm.pdf(edges, mean, sd)
binwidth = (len(edges)) / (max(edges) - min(edges))
Y = Y * binwidth
print "Binwidth is:", 1/binwidth
plt.plot(edges, Y)
plt.show()

source
share