This is a direct continuation of my recent question here, which is solved. I am re-posting the code here as well for integrity:
import numpy as np
from scipy.optimize import curve_fit
xdata = np.array([0.1639534, 0.2411005, 0.3130353, 0.3788510, 0.4381247, 0.5373147, 0.6135673, 0.6716365, 0.7506711, 0.8000908, 0.9000000])
ydata =np.array ([7.1257999E-04,9.6610998E-04,1.1894000E-03,1.3777000E-03,1.5285000E-03,1.7297000E-03,1.8226000E-03,1.8422999E-03,1.7741000E-03,1.6574000E-03,1.1877000E-03])
def func (x,a,b,c):
return a+b*x+c*x**3
popt, pcov =curve_fit(func,xdata,ydata,p0=(1,1,1))
with open('5fit','w') as outfile:
outfile.write(' '.join(str(val) for val in popt))
Now, for plotting those data, I use gnuplot
, as:
gnuplot> a=-5.20906980e-05
gnuplot> b=4.41458412e-03
gnuplot> c=-3.65246935e-03
gnuplot> p a+b*x+c*x**3 w l
I generally follow this for plotting a function or this for data file.
But now, I need to plot that function(a+b*x+c*x**3
) using those data given by popt
. I also need to save them in pdf/png format.
Kindly help me doing that.