Skip to content

Instantly share code, notes, and snippets.

@juanpabloaj
Created August 21, 2013 14:28
Show Gist options
  • Save juanpabloaj/6295191 to your computer and use it in GitHub Desktop.
Save juanpabloaj/6295191 to your computer and use it in GitHub Desktop.
scipy curve fit and plot
# http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt
def func(x, a, b, c):
return a * np.exp(-b*x) + c
x = np.linspace(0, 4, 50)
y = func(x, 2.5, 1.3, 0.5)
yn = y + 0.2 * np.random.normal(size=len(x))
popt, pcov = curve_fit(func, x, yn)
#print popt
plt.plot(x, yn, 'o', x, func(x, *popt))
plt.show()
@juanpabloaj
Copy link
Author

curve_fit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment