Scipy指数衰减曲线

时间:2018-02-11 22:43:33

标签: python scipy curve-fitting data-fitting model-fitting

我试图将我的数据点拟合到指数衰减曲线。所以,我的代码是:

import numpy as np
from scipy.optimize import curve_fit
import matplotlib.pyplot as plt


x = np.array([54338, 54371, 54547])
y = np.array([6.37468,6.36120,6.34980])

# prepare some data
x1 = np.array([54324,54332,54496, 54620, 54752, 54861, 54913, 54914, 54915, 54913, 54974, 55026, 55117, 55117 ])
y1 = np.array([6.40873, 5.00000, 5.00000, 6.32667, 6.29763, 6.29971, 5.00000, 6.29771, 6.29687, 6.32965, 6.28848, 6.27450,6.31405,6.19976])

xall = np.array([54338, 54371, 54547,54324,54332,54496, 54620, 54752, 54861, 54913, 54914, 54915, 54913, 54974, 55026, 55117, 55117 ])
yall = np.array([6.37468,6.36120,6.34980,6.40873, 5.00000, 5.00000, 6.32667, 6.29763, 6.29971, 5.00000, 6.29771, 6.29687, 6.32965, 6.28848, 6.27450,6.31405,6.19976 ])

t0=54322.13
def h(x1,a,b,c):
    return a*np.exp(-(x1-t0)/b)+c
lendata= len(x)


popt,pcov = curve_fit(h,xall,yall)
y_fit =(h(xall, *popt))

fig = plt.figure()

plt.plot(x, y, color='#5e3c99', ls='None',marker='o')
plt.plot(x1, y1, color='#e66101',ls='None',marker='o')
plt.plot(xall, h(xall, *popt), color='#377eb8')



plt.show()

我从Scipy的documents练习代码。一切看起来还不错,但我有一个非常奇怪的线条适合曲线拟合:

plot

我也检查了这个solution,但它没有那么多帮助。可能导致这个问题的原因是什么?

0 个答案:

没有答案