误差棒上限选择#

通过 errorbar 的参数 uplimslolims,演示如何选择性地绘制误差棒的下限和/或上限符号。

或者,您可以使用 2xN 的数值来仅在一个方向上绘制误差棒。

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
x = np.arange(10)
y = 2.5 * np.sin(x / 20 * np.pi)
yerr = np.linspace(0.05, 0.2, 10)

plt.errorbar(x, y + 3, yerr=yerr, label='both limits (default)')

plt.errorbar(x, y + 2, yerr=yerr, uplims=True, label='uplims=True')

plt.errorbar(x, y + 1, yerr=yerr, uplims=True, lolims=True,
             label='uplims=True, lolims=True')

upperlimits = [True, False] * 5
lowerlimits = [False, True] * 5
plt.errorbar(x, y, yerr=yerr, uplims=upperlimits, lolims=lowerlimits,
             label='subsets of uplims and lolims')

plt.legend(loc='lower right')
errorbar limits simple

类似地,xuplimsxlolims 可用于水平 xerr 误差棒。

fig = plt.figure()
x = np.arange(10) / 10
y = (x + 0.1)**2

plt.errorbar(x, y, xerr=0.1, xlolims=True, label='xlolims=True')
y = (x + 0.1)**3

plt.errorbar(x + 0.6, y, xerr=0.1, xuplims=upperlimits, xlolims=lowerlimits,
             label='subsets of xuplims and xlolims')

y = (x + 0.1)**4
plt.errorbar(x + 1.2, y, xerr=0.1, xuplims=True, label='xuplims=True')

plt.legend()
plt.show()
errorbar limits simple

参考

本示例展示了以下函数、方法、类和模块的使用

标签:组件:误差 绘图类型:误差棒 难度:初级

脚本运行总耗时:(0 分 1.058 秒)

由 Sphinx-Gallery 生成的画廊