Python: Curve fitting from data

628 views Asked by At

I am beginner about curve fitting in the Python. I want to fit my data with curve_fit. I have 3 data frames and 2 of them contains 3 rows and just one row has float number, others are Nan. My other data frame has 3 float rows. Like that:

     MJDMEAN         MJDMEANMAX      LUMINOSITYMAX
0    54960.007130    NaN             NaN
1    55179.630428    55179.630428    7.264769e+40   
2    51884.066424    NaN             NaN

I want to create fit from my data. My

pf = pd.read_csv('/home/foo/file.csv', sep=',', encoding ='utf-8')
##function is L(t) = Lmax(t)*(((MJDMEAN-(MJDMEANMAX- 100))/(MJDMEANMAX-100))**(-5/3))

def f(x, a, b):
    return a * (((x-(b-100))/(b-100))**(-1.67))
##creating fake data at below:
x = np.linspace((pf['MJDMEANMAX'][1]), (pf['MJDMEANMIN'][0]),10)
y = np.linspace((pf['LUMINOSITYMAX'][1]), (pf['LUMINOSITYMIN'][0]),10)
a, b = pf['LUMINOSITYMAX'][1], pf['MJDMEANMAX'][1]

popt, pcov = curve_fit(f, x, y)

curvefit = f(x,popt[0],popt[1])
plt.plot (x,y,curvefit)

But, I am having blank plot. Ho can I get the fit with that method? I get confused.

0

There are 0 answers