Я пытаюсь втиснуть гауссовскую модель lmfit в мои данные таким образом, чтобы пользователь отмечал точки фона, и когда он нажимает кнопку «fit», программа вписывает кривую в отмеченные места (аналогично изображение, которое я включил введите описание изображения здесь <- здесь) и распечатайте соответствующий отчет, и вот мой код: </p>
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from lmfit.models import GaussianModel
from matplotlib.widgets import Cursor, Button
x, y = np.loadtxt("fily3.txt", skiprows=1, unpack = True)
mod2 = GaussianModel()
pars = mod2.guess(y, x=x) #Estimate initial model parameter values from data
out = mod2.fit(y, pars, x=x) #Fit the model to the data using the supplied Parameters
fig, ax = plt.subplots()
print("Gaussian fit report \n")
print(out.fit_report(min_correl=0.25))
plt.plot(x, y, 'b')
plt.plot(x, out.best_fit, 'k--', label='best fit')
cursor = Cursor(ax,
horizOn=True, # Controls the visibility of the horizontal line
vertOn=True, # Controls the visibility of the vertical line
color='green',
linewidth=2.0
)
def onclick(event):
x1, y1 = event.xdata, event.ydata
print("X-Coordinate : ",x1," & ", "Y-Coordinate : ", y1)
fig.canvas.mpl_connect('button_press_event', onclick)
plt.title(" Gaussian model")
plt.xlabel("2-Theta")
plt.ylabel("Intensity")
plt.grid(True)
plt.show()
`