October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Plot Error Bars in Matplotlib with `plt.errorbar`

Add vertical and horizontal error bars in Matplotlib, choose the right input shape for symmetric or asymmetric uncertainty, and style intervals clearly with plt.errorbar.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use plt.errorbar(x, y, yerr=...) to add vertical uncertainty intervals to a Matplotlib plot, and xerr=... for horizontal intervals. Supply error magnitudes as a scalar or one value per point for symmetric bars, or as a two-row array for different lower and upper magnitudes. The examples below use the official Matplotlib 3.11.0 API.

Plot basic vertical error bars

Pass the data coordinates as x and y, then give yerr the vertical error magnitude or magnitudes. This example draws a marker at each point and adds caps to the error bars:

import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [2.0, 2.8, 4.2]
yerr = [0.2, 0.35, 0.25]

fig, ax = plt.subplots()
ax.errorbar(x, y, yerr=yerr, fmt='o', capsize=3)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()

The equivalent pyplot call is plt.errorbar(x, y, yerr=yerr, fmt='o', capsize=3). The object-oriented form, ax.errorbar(...), adds the plot to a particular axes.

Choose the error input shape

For either xerr or yerr, the error values are magnitudes, not signed offsets. Every value must be greater than or equal to zero. The official Matplotlib 3.11.0 errorbar reference accepts these forms:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Input Meaning Example
Scalar The same symmetric error for every data point. yerr=0.2
Array of shape (N,) A symmetric error for each of N data points. yerr=[0.2, 0.35, 0.25]
Array of shape (2, N) Different lower and upper error magnitudes at each point. Row 0 contains lower errors; row 1 contains upper errors. yerr=[[0.1, 0.2, 0.15], [0.3, 0.4, 0.25]]

Represent asymmetric errors

Put the lower magnitudes in the first row and the upper magnitudes in the second. For example:

lower_errors = [0.1, 0.2, 0.15]
upper_errors = [0.3, 0.4, 0.25]

ax.errorbar(x, y, yerr=[lower_errors, upper_errors], fmt='o', capsize=3)

Do not make the lower row negative to indicate direction. Matplotlib interprets the rows by position and requires nonnegative magnitudes.

Add horizontal, vertical, or combined intervals

yerr draws vertical intervals and xerr draws horizontal intervals. Supply both when each point needs uncertainty in both coordinates:

ax.errorbar(x, y, xerr=[0.1, 0.2, 0.15], yerr=[0.2, 0.35, 0.25], fmt='o', capsize=3)

Each error input should match the corresponding coordinate data: a scalar applies the same magnitude throughout, while arrays specify per-point magnitudes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Style the bars and markers

Use fmt to choose how the data points are shown, and use the error-bar options to control their appearance. The defaults and available parameters are described in the API reference.

  • fmt='o' uses circle markers; other Matplotlib format strings can select a different marker or line style.
  • fmt='none' (case-insensitive) draws only the error bars, without the data markers or connecting line.
  • ecolor sets the error-line color. If omitted, the data line color is used.
  • elinewidth and elinestyle set the error-line width and style.
  • capsize sets cap length in points. Its default follows rcParams['errorbar.capsize'], which the reference documents as 0.0; set it explicitly when you want visible caps.
  • capthick controls cap thickness, but legacy mew or markeredgewidth settings override it for backward compatibility.
  • barsabove=True places error bars above the plot symbols; the default is below them.

Thin bars when points overlap

Set errorevery=N to draw error bars at every Nth point. Use errorevery=(start, N) to choose a starting index and then draw every Nth bar. The data series itself remains present; only the error bars are thinned. This can help when intervals overlap or multiple series share x values.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Show one-sided limits

For censored values or other one-sided bounds, use lolims, uplims, xlolims, or xuplims to mark lower or upper limits for y or x. These flags add caret-style limit indicators rather than treating every value as an ordinary two-sided interval.

The names can be counterintuitive: lolims=True means the plotted y value is a lower limit of the true value, so Matplotlib draws an upward-pointing arrow. If the relevant axis is inverted, set its limits before calling errorbar(), as noted in the official reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep the statistical meaning explicit

errorbar() draws the magnitudes you supply; it does not determine whether they represent standard deviation, standard error, a confidence interval, or another quantity. State the quantity and how it was calculated in the surrounding text or legend. The same visual form can represent different kinds of uncertainty, so the label is part of making the plot interpretable.

Use the returned container or check version-specific behavior

The call returns an ErrorbarContainer containing the data line (Line2D), cap lines (Line2D objects), and error-bar line collections (LineCollection). That return value can be useful if later code needs to inspect or style the plotted components.

For polar plots, the 3.11.0 reference says caps and error lines are drawn in polar coordinates, a behavior introduced in Matplotlib 3.7. If a polar plot behaves unexpectedly, check the documentation for the Matplotlib version actually installed.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.