summaryrefslogtreecommitdiff
path: root/fit.py
blob: 1ecee1f31d9e0e1a656d5d9afdc025821f1c019a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from scipy.optimize import curve_fit
import numpy
import matplotlib.pyplot as pyplot


data_x = numpy.array([   10,  13,  17,  21,  24,  31,  36,  41 ])
data_y = numpy.array([ 1017, 898, 810, 715, 620, 547, 510, 500 ])

def func(x, a, b, c):
    return a * numpy.exp(-b*x)-c

popt, pcov = curve_fit(func, data_x, data_y, maxfev=5000)
trial_x = numpy.linspace(0, 50, 200)
trial_y = func(trial_x, *popt)

print popt

pyplot.figure()
pyplot.plot(data_x, data_y, 'ro', label='Data')
pyplot.plot(trial_x, trial_y, 'b-', label="Exp Fit")
pyplot.legend()
pyplot.show()