Python:根据数据拟合曲线

时间:2016-12-20 11:55:59

标签: python curve-fitting data-fitting

我是Python中曲线拟合的初学者。我想用curve_fit填充我的数据。我有3个数据帧,其中2个包含3行,只有一行有浮点数,其他是Nan。我的其他数据框有3个浮动行。像那样:

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

我想从我的数据中创建合适的。我的

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)

但是,我的情节空白。我可以使用那种方法吗?我感到困惑。

0 个答案:

没有答案