matplotlib errorbar: no line, asymmetric, bar chart, colours (tested)
Use fmt="o" for markers without a connecting line (or fmt="none" for bars only), yerr=[lower, upper] for asymmetric errors, and capsize=5 to draw caps (they are off by default).
ax.errorbar() and ax.bar(yerr=...) measured with matplotlib 3.11.2 (Agg backend) and NumPy 2.5.4 on Python 3.13.5. Line styles, bar end points and error messages below were read from the returned artists.
1. matplotlib errorbar without line: fmt="o" or fmt="none"
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [2.0, 3.5, 3.0, 4.5]
err = [0.2, 0.4, 0.3, 0.5]
fig, ax = plt.subplots()
for fmt in ["", "o", "none"]:
c = ax.errorbar(x, y, yerr=err, fmt=fmt)
line = c.lines[0]
print(f"fmt={fmt!r:7} data line: {line is not None}",
"" if line is None else f"linestyle={line.get_linestyle()!r} marker={line.get_marker()!r}")
c = ax.errorbar(x, y, yerr=err, linestyle="none", marker="s")
print("linestyle='none':", repr(c.lines[0].get_linestyle()), repr(c.lines[0].get_marker()))
Output:
fmt='' data line: True linestyle='-' marker='None'
fmt='o' data line: True linestyle='None' marker='o'
fmt='none' data line: False
linestyle='none': 'None' 's'
With the default fmt="" errorbar draws a solid line through the points. fmt="o" gives markers and no connecting line; fmt="none" draws only the error bars (no data line at all, c.lines[0] is None). linestyle="none" with a marker does the same as fmt="o".
2. Asymmetric error bars: yerr=[lower, upper]
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1, 2, 3])
y = np.array([5.0, 7.0, 6.0])
lower = np.array([0.5, 1.0, 0.2])
upper = np.array([1.5, 0.5, 2.0])
fig, ax = plt.subplots()
c = ax.errorbar(x, y, yerr=[lower, upper], fmt="o", capsize=4)
segs = c.lines[2][0].get_segments()
for s in segs:
print("bar from", s[0][1], "to", s[1][1])
for bad in ([lower, upper, lower], np.column_stack([lower, upper]), [-0.5, 1.0, 0.2]):
try:
ax.errorbar(x, y, yerr=bad)
except ValueError as e:
print("ValueError:", e)
Output:
bar from 4.5 to 6.5
bar from 6.0 to 7.5
bar from 5.8 to 8.0
ValueError: 'yerr' (shape: (3, 3)) must be a scalar or a 1D or (2, n) array-like whose shape matches 'y' (shape: (3,))
ValueError: 'yerr' (shape: (3, 2)) must be a scalar or a 1D or (2, n) array-like whose shape matches 'y' (shape: (3,))
ValueError: 'yerr' must not contain negative values
Pass a (2, n) array: the first row is the distance below each point, the second the distance above. Both are offsets, not absolute limits: to plot from absolute bounds use yerr=[y - lo, hi - y]. A (n, 2) array (e.g. from column_stack) is rejected with the shape error; transpose it with .T. Negative values raise 'yerr' must not contain negative values, which is what you get if lo is above y.
3. matplotlib bar chart with error bars and caps
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
labels = ["A", "B", "C"]
means = [20, 35, 30]
sd = [2, 3, 4]
fig, ax = plt.subplots()
bars = ax.bar(labels, means, yerr=sd, capsize=5, ecolor="black")
print(type(bars).__name__, "errorbar:", type(bars.errorbar).__name__)
caps = bars.errorbar.lines[1]
print("caps drawn:", len(caps))
fig2, ax2 = plt.subplots()
bars2 = ax2.bar(labels, means, yerr=sd)
print("caps without capsize:", len(bars2.errorbar.lines[1]))
print("rcParams errorbar.capsize:", plt.rcParams["errorbar.capsize"])
Output:
BarContainer errorbar: ErrorbarContainer
caps drawn: 2
caps without capsize: 0
rcParams errorbar.capsize: 0.0
ax.bar takes yerr directly and stores the bars in bars.errorbar. Caps are off by default (errorbar.capsize is 0.0): pass capsize=5, or set plt.rcParams["errorbar.capsize"] for every plot. The same capsize= works on ax.errorbar.
4. errorbar with different colours per point (scatter)
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2.0, 3.0, 2.5]
err = [0.3, 0.2, 0.4]
colors = ["red", "green", "blue"]
fig, ax = plt.subplots()
try:
ax.errorbar(x, y, yerr=err, fmt="o", c=colors)
except Exception as e:
print(type(e).__name__ + ":", e)
c = ax.errorbar(x, y, yerr=err, fmt="none", ecolor=colors)
print("ecolor list ok, bar colors:", len(c.lines[2][0].get_colors()))
sc = ax.scatter(x, y, c=colors, zorder=3)
print("scatter on top:", type(sc).__name__)
c = ax.errorbar(x, y, xerr=0.1, yerr=err, fmt="o")
print("bar collections with xerr+yerr:", len(c.lines[2]))
Output:
ValueError: ['red', 'green', 'blue'] is not a valid value for color: supported inputs are (r, g, b) and (r, g, b, a) 0-1 float tuples; '#rrggbb', '#rrggbbaa', '#rgb', '#rgba' strings; named color strings; string reprs of 0-1 floats for grayscale values; 'C0', 'C1', ... strings for colors of the color cycle; and pairs combining one of the above with an alpha value
ecolor list ok, bar colors: 3
scatter on top: PathCollection
bar collections with xerr+yerr: 2
errorbar has a single marker colour, so c=[...] raises ValueError: ... is not a valid value for color. ecolor does accept a list for the bars. For coloured points, draw the bars with fmt="none" and put ax.scatter(..., c=colors, zorder=3) on top. xerr and yerr can be combined; each gets its own bar collection.
Related: matplotlib savefig dpi, size, transparent, matplotlib not showing plot, NumPy RuntimeWarning.
Frequently asked questions
How do I remove the line in matplotlib errorbar?
Pass fmt='o' (markers only) or fmt='none' (error bars only). The default fmt='' draws a solid line.
How do I plot asymmetric error bars in matplotlib?
yerr=[lower, upper], a (2, n) array of distances below and above each point. A (n, 2) array raises a shape ValueError; transpose it.
Why are there no caps on my error bars?
errorbar.capsize defaults to 0.0. Pass capsize=5 to errorbar() or bar().
Written with AI assistance. Measured on 2026-10-23 with matplotlib 3.11.2 (Agg backend) and NumPy 2.5.4 on Python 3.13.5. Each block was run verbatim and the output pasted unedited. PlainTables is our extension; Python and matplotlib are free.