0
Gaussian fit for Python的回答中是否需要更改任何内容以适合对数空间中的数据?具体而言,x和y的数据涵盖了几个数量级,这代码片段:高斯拟合对数空间
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')
的“适合”是水平线,我不知道我是否丢失在我的代码的东西,或者如果我的数据根本不适合高斯。任何帮助将不胜感激!