【发布时间】:2016-03-02 02:53:18
【问题描述】:
在Gaussian fit for Python 的答案中是否需要更改任何内容以适应日志-日志空间中的数据?具体来说,对于覆盖几个数量级的x和y数据以及这段代码sn-p:
from scipy.optimize import curve_fit
from scipy import asarray as ar,exp
def gaus(x,a,x0,sigma):
return a*exp(-(x-x0)**2/(2*sigma**2))
b=np.genfromtxt('Stuff.dat', delimiter=None, filling_values=0)
x = b[:,0]
y = b[:,1]
n = len(x) #the number of data
mean = sum(x*y)/n #note this correction
sigma = sum(y*(x-mean)**2)/n #note this correction
popt,pcov = curve_fit(gaus,x,y,p0=[max(y),mean,sigma])
ax = pl.gca()
ax.plot(x, y, 'r.-')
ax.plot(x,gaus(x,*popt),'ro:')
ax.set_xscale('log')
ax.set_yscale('log')
“拟合”是水平线,我不确定我的代码中是否遗漏了某些内容,或者我的数据是否根本不适合高斯。任何帮助将不胜感激!
【问题讨论】: