【问题标题】:Can I plot the error band using the uncertainties of curve fitting (Python)?我可以使用曲线拟合的不确定性(Python)绘制误差带吗?
【发布时间】:2021-10-16 21:14:47
【问题描述】:
这是我的数据的最小二乘二次拟合结果:y = 0.06(+/- 0.16)x**2-0.65(+/-0.04)x+1.2(+/-0.001)。我想知道是否有直接的方法来绘制拟合以及误差带?我找到了一个similar example,它使用了plt.fill_between 方法。但是,在该示例中,边界是已知的,而在我的情况下,我不太确定与边界相对应的确切参数。我不知道我是否可以使用plt.fill_between 或其他方法。谢谢!
【问题讨论】:
标签:
python
matplotlib
curve-fitting
【解决方案1】:
您可以使用seaborn.regplot 计算拟合并直接绘制它(order=2 是二阶拟合):
这是一个虚拟示例:
import seaborn as sns
import numpy as np
xs = np.linspace(0, 10, 50)
ys = xs**2+xs+1+np.random.normal(scale=20, size=50)
sns.regplot(x=xs, y=ys, order=2)