File: plot_fit2.py

package info (click to toggle)
lmfit-py 0.9.11%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,908 kB
  • sloc: python: 10,121; makefile: 114; sh: 55
file content (28 lines) | stat: -rw-r--r-- 788 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python

from matplotlib import pyplot as plt
import numpy as np

import lmfit

# construct data
x = np.linspace(-4, 4)
y = np.exp(-x**2)

noise = np.random.randn(x.size) * 0.1
y += noise

# define model and fit
model_gaussian = lmfit.models.GaussianModel()
model_gaussian.guess(y, x=x)
fit_gaussian = model_gaussian.fit(y, x=x, weights=1/noise**2)

# plot the with with customization
fig, gridspec = fit_gaussian.plot(fig_kws=dict(figsize=[8, 7]),
                                  ax_fit_kws=dict(title='The gaussian fit'),
                                  initfmt='k:', datafmt='ks',
                                  fit_kws=dict(lw=2, color='red'),
                                  data_kws=dict(ms=8, markerfacecolor='white'))

fig.set_tight_layout(True)
plt.show()