I have a plot with two data sets which produces a slight gradient, where a curved line of best fit may be overplotted.
At the moment I have only managed to get a straight line of best fit. I understand scipy.optimize.curve_fit
should be able to help me, but this requires me to know the function I want to overplot (I think).
Below are my code and plots. How would one go about creating a curved plot for these data sets?
plt.figure(figsize=(15,6.6))
pl.subplot(1,2,1)
plt.plot(gg,AA, 'kx')
plt.xlabel('x')
plt.ylabel('y')
plt.gca().invert_yaxis()
y=AA
x=gg
fit=pl.polyfit(x,y,1)
#slope, fit_fn=pl.poly1d(fit)
fit_fn=pl.poly1d(fit)
scat=pl.plot(x,y, 'kx', x,fit_fn(x), '-b' )
pl.subplot(1,2,2)
pl.plot(LL,pp, 'kx')#shows points with no removal or bestfit
plt.gca().invert_yaxis()
plt.savefig('1.jpg')
plt.show()
It should be noted that there is possibly no curve but I want to discover if there is one which would fit.