title: overplot poisson distribution to histogram
body: <p>I know there are previous questions related to the topic but I can't find the specifics of my question. I'm trying to overplot a Poisson distribution on a histogram. The first thing I tried was using the poisson function from the stats module in scipy:</p>
  
  <pre><code>import numpy
  from scipy.stats import poisson
  
  mu = mean(data)
  n, bins, patches = pyplot.hist(data, 20, normed = 1)
  pyplot.plot(bins, poisson.pmf(bins, mu), 'r-')
  pyplot.show()
  </code></pre>
  
  <p>However as shown in the figure (in blue the histogram of my data), I get the red plot which has three weird peaks.</p>
  
  <p><a href="https://i.stack.imgur.com/h8R2N.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h8R2N.png" alt="The histogram in blue represents my data. The red line is the Poisson function using scipy.stats"></a></p>
  
  <p>Thus I tried to write my own poisson distribution function:</p>
  
  <pre><code>def poisson(mu, x):
      from scipy.misc import factorial
      return numpy.exp(-mu) * mu**x * factorial(x)**-1
  
  y = poisson(mu, bins)
  </code></pre>
  
  <p>But when I try to print it I get an array of nan's. Am I doing something wrong? Or is it that the numbers in the bins are too large? </p>
  
  <pre><code>print y    
  [ nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan  nan nan nan  nan  nan  nan  nan  nan]
  </code></pre>
  
  <p>However when printing the results from stats.poisson I get:</p>
  
  <pre><code>[3.25452236e-06   0.00000000e+00   0.00000000e+00   0.00000000e+00
   0.00000000e+00   3.63110218e-04   0.00000000e+00   0.00000000e+00
   0.00000000e+00   0.00000000e+00   5.24385396e-03   0.00000000e+00
   0.00000000e+00   0.00000000e+00   0.00000000e+00   1.06061293e-02
   0.00000000e+00   0.00000000e+00   0.00000000e+00   0.00000000e+00
   3.23183010e-03]
  </code></pre>