title: Histogram fitting with python
body: <p>I've been surfing but haven't found the correct method to do the following.</p>
  
  <p>I have a histogram done with matplotlib:</p>
  
  <pre><code>hist, bins, patches = plt.hist(distance, bins=100, normed='True')
  </code></pre>
  
  <p>From the plot, I can see that the distribution is more or less an exponential (Poisson distribution). How can I do the <em>best fitting</em>, taking into account my hist and bins arrays?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I am using the following approach:</p>
  
  <pre><code>x = np.float64(bins) # Had some troubles with data types float128 and float64
  hist = np.float64(hist)
  myexp=lambda x,l,A:A*np.exp(-l*x)
  popt,pcov=opt.curve_fit(myexp,(x[1:]+x[:-1])/2,hist)
  </code></pre>
  
  <p>But I get</p>
  
  <pre><code>---&gt; 41 plt.plot(stats.expon.pdf(np.arange(len(hist)),popt),'-')
  
  ValueError: operands could not be broadcast together with shapes (100,) (2,)
  </code></pre>