Matplotlib:表示测量精度的图

数据挖掘 错误处理
2022-02-18 10:53:57

我有一些有一定误差的数据,并且正在使用 numpy 数组来绘制该数据。假设精度是 0.05 或 0.03 克,那么数据将类似于

[4.0±0.05, 3.05±0.03]

我怎样才能在我的绘图上显示这个(在 x 轴或 y 轴上。如果两者都是,那就更好了)?

我使用 pyplot,我的操作系统是 macOS

1个回答

可以使用matplotlib.axes.Axes.errorbar类。

从文档中的这个例子

# example error bar values that vary with x-position
error = 0.1 + 0.2 * x

fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
ax0.errorbar(x, y, yerr=error, fmt='-o')
ax0.set_title('variable, symmetric error')

致谢:感谢Emre