title: Fitting an un-normalised distribution with scipy.stats
body: <p>I'm tryng to fit a histogram but the fit only works with normalised data, i.e. with option <code>normed=True</code> in the histogram. Is there a way of doing this with scipy stats (or other method)? Here is a MWE using a uniform distribution:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import random
  from scipy.stats import uniform
  
  data = []
  for i in range(1000):
      data.append(random.uniform(-1,1))
  
  loc, scale = uniform.fit(data)
  
  x = np.linspace(-1,1, 1000)
  y = uniform.pdf(x, loc, scale)
  
  plt.hist(data, bins=100, normed=False)
  plt.plot(x, y, 'r-')
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/1XFxh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1XFxh.png" alt="enter image description here"></a></p>
  
  <p>I also tried defining my own function (below) but I'm getting a bad fit.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  import random
  from scipy import optimize
  
  data = []
  for i in range(1000):
      data.append(random.uniform(-1,1))
  
  def unif(x,avg,sig):
      return avg*x + sig
  
  y, base = np.histogram(data,bins=100)
  x = [0.5 * (base[i] + base[i+1]) for i in xrange(len(base)-1)]
  
  popt, pcov = optimize.curve_fit(unif, x, y)
  x_fit = np.linspace(x[0], x[-1], 100)
  y_fit = unif(x_fit, *popt)
  
  plt.hist(data, bins=100, normed=False)
  plt.plot(x_fit, y_fit, 'r-')
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/mNydr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mNydr.png" alt="enter image description here"></a></p>