im pretty new lerning how to use python and i have this problem. I need to plot some data from a csv file and fit a gaussian curve to it. But for some reason, the fit is just a straight line.
Here's my code
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy.optimize as opt
from scipy.optimize import curve_fit
data = pd.read_csv('DRXRed.csv',delimiter=",", names=['2T', 'I'])
plt.xlabel('2\u03B8[Grados]')
plt.ylabel('Intensidad[u.a]')
plt.title('Pico Máximo Difractograma Sr\u2082bCoO\u2086')
plt.grid(visible=True)
def Gauss(x, A, B):
y = A*np.exp(-1*B*x**2)+2000
return y
parameters, covariance = curve_fit(Gauss, data['2T'],data['I'])
fit_A = parameters[0]
fit_B = parameters[1]
fit_y = Gauss(data['2T'], fit_A, fit_B)
print(fit_A)
print(fit_B)
plt.plot(data['2T'], data['I'],color="r", label='data')
plt.plot(data['2T'], fit_y, '-', label='fit')
plt.savefig('Pico.png', dpi=1080)
And here's my function
It shows me this warning but i dont know what it means
/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/scipy/optimize/minpack.py:833: OptimizeWarning: Covariance of the parameters could not be estimated
warnings.warn('Covariance of the parameters could not be estimated',
1.0
1.0
I would be very grateful for any help :)