我想拟合高斯,但变量 cen 和 cen2 必须不断。
from pylab import *
import matplotlib.mlab
from lmfit import Model
def gaussian(x, amp, cen, wid,amp2,cen2,wid2):
return (amp/(sqrt(2*pi)*wid)) * exp(-(x-cen)**2 /(2*wid**2))+
(amp2/(sqrt(2*pi)*wid2)) * exp(-(x-cen2)**2 /(2*wid**2))
model = Model(gaussian)
model.set_param_hint('amp',min=1.4, max=1.48)
model.set_param_hint('amp2',min=0.00003,max=0.00005)
parameters = model.make_params( amp=1.46, cen=0, wid=1, amp2=0.00005,
cen2=10,wid2=5)
result = model.fit(y, parameters, x=x)
模型拟合高斯,但将中心设置为 f.ex。5.
print(result.fit_report())
#plt.yscale('log')
#plt.ylim(((0,0.0004)))
plt.scatter(x, y, s=0.7)
plt.plot(x, result.best_fit, 'r-')
plt.fill_between(x, result.best_fit-0.03, result.best_fit+0.03,
color="#ABABAB",alpha=0.5)
plt.show()
我怎样才能做到这一点?