It took me some time but I have used the code below to create myself a Gaussian fit for my x,y data set.
import matplotlib.pyplot as plt
import numpy as np
from scipy.optimize import curve_fit
def Gauss(x, a, x0, sigma, offset):
return a * np.exp(-(x - x0)**2 / (2 * sigma**2)) + offset
x, y = np.random.random(100), np.random.random(100)
popt, pcov = curve_fit(Gauss, x, y, p0=[np.max(y), np.median(x), np.std(x), np.min(y)])
plt.plot(x, y, 'b+:', label='data')
x_fit = np.linspace(np.min(x), np.max(x), 1000)
plt.plot(x_fit, Gauss(x_fit, *popt), 'r-', label='fit')
plt.legend()
plt.title('Something')
plt.xlabel('Anotherthing')
plt.ylabel('Athing')
plt.show()
I can see my fit is well done and see the graph and everything.
What I would like to know now is how can I print out the results of this fit on my screen such as the max value at x on fit's max point, the estimated error and etc?
Is these information accessible? If so, is there a way to print out this information? If not, can someone point me to the right direction about finding the error of the fit please?