File: example_use_pandas.py

package info (click to toggle)
lmfit-py 1.0.1-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,544 kB
  • sloc: python: 11,025; makefile: 114; sh: 43
file content (28 lines) | stat: -rw-r--r-- 801 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
"""
Fit with Data in a pandas DataFrame
===================================

Simple example demonstrating how to read in the data using pandas and supply
the elements of the DataFrame from lmfit.

"""
import matplotlib.pyplot as plt
import pandas as pd

from lmfit.models import LorentzianModel

###############################################################################
# read the data into a pandas DataFrame, and use the 'x' and 'y' columns:
dframe = pd.read_csv('peak.csv')

model = LorentzianModel()
params = model.guess(dframe['y'], x=dframe['x'])

result = model.fit(dframe['y'], params, x=dframe['x'])

###############################################################################
# and gives the plot and fitting results below:
result.plot_fit()
plt.show()

print(result.fit_report())