Show uncertainty with error bars and bands

3.11.2

Plot lower and upper error distances and label what uncertainty represents.

On this page

Use nonnegative distances from the estimate

Pass yerr as error distances, measured from each estimate. With asymmetric intervals, pass lower distances first and upper distances second. Label whether the bars show confidence intervals, standard error, or another quantity.

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.errorbar(["A", "B"], [8, 10], yerr=[[1, 2], [2, 1]], fmt="o", capsize=5)
ax.set(ylabel="Estimated units", title="Estimates with illustrative intervals")
plt.show()
Store A’s estimate is 8, with bounds 7 and 10. Store B’s is 10, with bounds 8 and 11. Download image

Show a continuous interval

fill_between draws a band between lower and upper values along x. Use it for an interval that varies over time, and align each lower and upper value with the matching x position.

Official references