aboutsummaryrefslogtreecommitdiff
path: root/processing/fit_function.py
blob: 247b4768dcdb3b1ee125712f6cec57780c3268d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# import
import os
import numpy as np
import matplotlib.pyplot as plt
import WrightTools as wt
from WrightTools import fit
# define
here = os.path.abspath(os.path.dirname(__file__))
# noisey gaussian
xi = np.linspace(-100, 100, 25)
yi = 20*np.exp(-0.5*((xi-5)/20.)**2)
yi = np.random.poisson(yi)
plt.scatter(xi, yi)
# fitted
g = wt.fit.Gaussian()
ps = g.fit(yi, xi)
xi = np.linspace(-100, 100, 101)
model = g.evaluate(ps, xi)
# plot
plt.plot(xi, model)
wt.artists.savefig(os.path.join(here, 'fit_function.png'))