我的项目有一个小问题,因为我有一组数据,我绘制它,以得到2条曲线,我想用指数曲线拟合这个曲线。
我看了这个帖子:fitting exponential decay with no initial guessing。 但我的例子有点不同。
这就是我所得到的数据:
我的脚本如下:
mask_G = np.bitwise_and( tbdata['G'] < 99.99, tbdata['GERR'] < 0.2)
mask_R = np.bitwise_and( tbdata['R'] < 99.99, tbdata['RERR'] < 0.2)
G_corrected = tbdata[mask_G]
R_corrected = tbdata[mask_R]
fig13 = plt.gcf()
fig13.set_size_inches(16, 9)
fig13, (ax1,ax2) = plt.subplots(1,2)
fig_error_g = ax1.plot(G_corrected['G'], G_corrected['GERR'], '.')
ax1.set_xlabel('G')
ax1.set_ylabel('GERR')
ax1.set_title('Evolution de GERR en fonction de G')
fig_error_r = ax2.plot(R_corrected['R'], R_corrected['RERR'], '.')
ax2.set_xlabel('R')
ax2.set_ylabel('RERR')
ax2.set_title('Evolution de RERR en fonction de R')
fig13.tight_layout()
plt.savefig('graphique.png')
plt.show()
我试着写这篇文章,是基于scipy doc的:
^{pr2}$但我得到:
/home/user/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/scipy/optimize/minpack.py:601: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
你知道我该怎么处理吗?
非常感谢;)
编辑:
我试着把我的情节安排成那样:
mask_G = np.bitwise_and( tbdata['G'] < 99.99, tbdata['GERR'] < 0.2)
mask_R = np.bitwise_and( tbdata['R'] < 99.99, tbdata['RERR'] < 0.2)
G_corrected = tbdata[mask_G]
R_corrected = tbdata[mask_R]
params = np.polyfit(G_corrected['G'], np.log(G_corrected['GERR']),1)
a = params[0]
A = np.exp(params[1])
fig13 = plt.gcf()
fig13.set_size_inches(16, 9)
fig13, (ax1,ax2) = plt.subplots(1,2)
fig_error_g = ax1.plot(G_corrected['G'], (G_corrected['GERR']), '.')
fig_error_g = ax1.plot(G_corrected['G'], (A*np.exp(a*G_corrected['G'])),'.')
ax1.set_xlabel('G')
ax1.set_ylabel('GERR')
ax1.set_title('Evolution de GERR en fonction de G')
fig_error_r = ax2.plot(R_corrected['R'], np.log(R_corrected['RERR']), '.')
ax2.set_xlabel('R')
ax2.set_ylabel('RERR')
ax2.set_title('Evolution de RERR en fonction de R')
fig13.tight_layout()
plt.savefig('graphique.png')
plt.show()
我得到:
你觉得结果怎么样?
最简单的方法是对绘图应用对数比例。正如您所知道的log(exp(x))=x,也就是说,如果您将log()应用于y值并绘制出一个线性图。一旦你有了它,你就可以用你的线性工具箱(Gaussian Least Square method)来适应它。得到的斜率是exp(ax)中的前置因子,您可以尝试获得它。在
如果您对x轴有另一个依赖关系,那么最好对数据进行日志日志绘图,以找出所有依赖关系。在
相关问题 更多 >
编程相关推荐