Created
August 21, 2013 14:28
-
-
Save juanpabloaj/6295191 to your computer and use it in GitHub Desktop.
scipy curve fit and plot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
Author
juanpabloaj
commented
Aug 21, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment