Firstly try not to increase maxfev
so large, this is usually a sign something else is going wrong! Playing around I can get a fit by the following addition:
def f(x, b, a, k):
return (b/(np.sqrt(1 + a*((k-x)**2))))
popt, pcov = curve_fit(f, x, y, p0=[20, 600.0, 35.0])
Firstly give the fitting function you have given has a maximum of 1, since the peak in your data is 600, it will never fit. So I added an overall factor b
. Secondly , try to help poor old curve_fit out. If by eye you can see it peaks at x~35
then tell it through the p0
. This requires some intuition as to how the function works but is very important if your going to use a curve fitting function.