如何解决在 Python 中在两个轴上拟合具有不对称误差的数据
我有6个参数形式的数据:x,y,x+错误,x-错误,y+错误,y-错误。我想找到最适合这个数据集的。我正在尝试使用 scipy.optimize.curve_fit 但它不允许我选择数据中的错误(我认为)。我试图找出一种方法,我发现在 curve_fit 中有一个名为 sigma 的函数,它执行类似的操作,但仅用于一个轴上的错误。在考虑数据点的误差的同时,有什么方法可以找到最适合数据的吗?
Attached is the scattered plot of the data including the error bars: 我想拟合那些红色散点。
另外,这里是没有误差条的 scipy fit 代码,以防万一:
#Import the Data
obs0x,xerr0_plus,xerr0_minus,obs0y,yerr_plus,yerr_minus=np.loadtxt("Mhratioz6",unpack='true')
#define the function to fit
def func(x,a,b):
return (np.log10(a)+(b*(x-12))+np.log10(10**(8+c)))
return ((x/1e12)**a)*(b)*(10**(8+c))
return a+(b*x)
#define the data to be fit
xdata=np.log10(obs0x)
ydata=np.log10(obs0y)
p0=[-1,1.65,0]
#Fit for the parameters a,b,c of the function func:
popt,pcov = curve_fit(func,xdata,ydata)
print("[a,b]=",popt)
plt.figure(figsize=(5,5))
plt.loglog(10**xdata,10**func(xdata,*popt),'r-',label='scipy fit')
#plt.loglog(m,func(m,label='Scipy-fit')
plt.scatter(obs0x,s=2)
plt.ylim(1e6,1e11)
plt.xlim(1e11,1e14)
plt.xlabel('x')
plt.ylabel('y')
plt.title("z=0 Observations")
plt.legend()
plt.show()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。