DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk2 min

Create a Scatter Plot with Error Bars in Python Matplotlib

Use Matplotlib’s errorbar() method to create a marker-only scatter plot with horizontal or vertical uncertainty bars, including asymmetric errors.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Matplotlib’s Axes.errorbar() method to plot data points with horizontal and/or vertical error bars. For a marker-only scatter-style plot, set fmt='o' and linestyle='none'.

Make a scatter plot with vertical error bars

This example adds symmetric y-error bars to four points. The values in yerr are the uncertainty magnitudes for each point.

import matplotlib.pyplot as plt

x = [1, 2, 3, 4]
y = [2.1, 2.8, 3.2, 4.3]
yerr = [0.2, 0.3, 0.15, 0.25]

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

fmt='o' selects circular data markers, and linestyle='none' prevents Matplotlib from connecting them. capsize=3 sets the cap length. The default cap size is 0.0, so specify a value when you want visible caps. Matplotlib errorbar API

Choose the right error-array shape

Error amounts must be nonnegative. A scalar applies the same symmetric error to every point; an array with one value per point gives each point its own symmetric error. Use a two-row array when lower and upper errors differ. Matplotlib errorbar API Matplotlib error-bar examples

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Input shape Meaning
Scalar Same symmetric error magnitude for every point.
(N,) One symmetric error magnitude per point; N is the number of data points.
(2, N) Asymmetric errors per point: first row is the lower amount, second row is the upper amount.

For example, pass separate lower and upper y-error magnitudes in that order:

lower = [0.1, 0.2, 0.1, 0.15]
upper = [0.25, 0.3, 0.2, 0.3]

ax.errorbar(x, y, yerr=[lower, upper], fmt='o', linestyle='none')

Do not represent a downward error with a negative number. Supply its positive magnitude in the lower row instead; reversing the rows swaps the intended lower and upper extents.

Add horizontal error bars or omit markers

Pass xerr for horizontal uncertainty and yerr for vertical uncertainty. You can provide either argument alone or both:

ax.errorbar(x, y, xerr=xerr, yerr=yerr, fmt='o', linestyle='none')

To draw error bars without data markers, use fmt='none'. For example: ax.errorbar(x, y, yerr=yerr, fmt='none'). Matplotlib errorbar API

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

Adjust the appearance and reduce clutter

  • capsize sets the length of the end caps.
  • ecolor sets the error-bar color.
  • errorevery displays error bars for a subset of data points when showing them all would make the plot difficult to read.

These options change the display, not the error magnitudes. See the errorbar API reference for the complete parameter list.

When to combine scatter() and errorbar()

Axes.errorbar() draws markers or lines along with error bars, making it the direct choice for a basic scatter plot with uncertainty. Use Axes.scatter() when you need its per-point marker-size or color controls. Because these are separate methods, you can layer a scatter call for the points with an errorbar call for the bars, suppressing the latter’s markers with fmt='none'. Matplotlib errorbar API Matplotlib scatter API

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

One-sided limits and inverted axes

If you use one-sided limit indicators on an inverted axis, set the axis limits before calling errorbar(). Matplotlib’s API notes that the order matters for these limit markers. Matplotlib errorbar API

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.

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.