File: plot_fit.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 (29 lines) | stat: -rw-r--r-- 611 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
29
#!/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 = lmfit.models.GaussianModel()
model.guess(y, x=x)
fit = model.fit(y, x=x, weights=1/noise**2)

fig, gridspec = fit.plot()

# customize plot post-factum
ax_residuals, ax_fit = fig.get_axes()
ax_residuals.set_title('The residuals')
ax_fit.set_title('An example gaussian fit')
ax_residuals.get_legend().set_visible(False)
ax_fit.get_legend().texts[0].set_size('small')

plt.show()