title: How to define function for scipy.optimize.curve_fit?
body: <p>I have been trying to make a curve fit for my histogram using scipy.optimize.curve_fit. Here is the sample code I am working on:</p>
  
  <pre><code>def gaussian(x,a,b,c):
      return a * exp(-(x - b)**2 / c**2) 
  
  def curvefit(gaussian, x, y,sigma):
      popt, pcov = curve_fit(gaussian, x, y, p0 = [1, mean, sigma])
      image = plt.plot(x, gauss_function(x, *popt), label='fit')
  </code></pre>
  
  <p>Where x is the binned x values (output from my histogram), y is the weight corresponding to those binned x (output from histogram as well). While running the code, I keep getting an error: </p>
  
  <pre><code>global name 'a' is not defined
  </code></pre>
  
  <p>And i understand why this error arouse but cannot find a way to fix it. Since curve_fit has the 1st parameter as a callable function, I don't know how to specify that in Python (seems like the program is reading the output of my gaussian function as a value). Thank you very much.</p>