Say you’re charting 2026 weekend hotel rates, and Seattle’s typical price sits $37.50 above the cheap end but $90.75 below the expensive end. A single plus-or-minus number can’t show that.
In this tutorial, I’ll draw Matplotlib asymmetric error bars by passing yerr=[lower, upper] to errorbar(), where both are distances from each point.
Every chart below ran on Matplotlib 3.11.2 on Python 3.12.5.
The sample hotel data we’ll use
I made up one small dataset for March 2026: a median weekend rate plus a low and high rate for five US cities.
Matplotlib wants distances, not prices, so save this as hotel_rates.py. It subtracts, and every later script imports from it:
import numpy as np
cities = ["Austin", "Denver", "Phoenix", "Seattle", "Tampa"]
median = np.array([189.50, 174.00, 162.75, 221.25, 156.50])
low = np.array([152.25, 141.50, 128.00, 183.75, 131.25])
high = np.array([268.75, 239.25, 251.50, 312.00, 224.75])
lower, upper = median - low, high - median
if __name__ == "__main__":
print("lower:", lower.tolist())
print("upper:", upper.tolist())
print("yerr shape:", np.array([lower, upper]).shape)
Output:
lower: [37.25, 32.5, 34.75, 37.5, 25.25]
upper: [79.25, 65.25, 88.75, 90.75, 68.25]
yerr shape: (2, 5)

That (2, N) shape is the whole trick: the first row goes below each point and the second goes above. For equal errors, my guide to Matplotlib error bars covers the basics.
Method 1: Plot asymmetric error bars with errorbar() (Recommended)
Use this for points or lines. Same hotel data:
import matplotlib.pyplot as plt
from hotel_rates import cities, median, lower, upper
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
ax.errorbar(cities, median, yerr=[lower, upper], fmt="o", capsize=6)
ax.set_title("Weekend Hotel Rates, March 2026")
ax.set_ylabel("Rate (USD)")
plt.show()

How does this code work? fmt="o" draws dots without a connecting line, and capsize=6 adds the small end caps.
Austin’s bar runs 37.25 down and 79.25 up from 189.50. If you’d rather keep a true scatter, see error bars on a Matplotlib scatter plot.
Method 2: Add asymmetric error bars to a bar chart
Use this when readers expect bars, as in a report. Same five cities, with ax.bar() taking the same yerr list:
import matplotlib.pyplot as plt
from hotel_rates import cities, median, lower, upper
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
ax.bar(cities, median, yerr=[lower, upper], capsize=6, color="#4C78A8")
ax.set_title("Weekend Hotel Rates, March 2026")
ax.set_ylabel("Rate (USD)")
plt.show()

How does this code work? bar() forwards yerr and capsize to the same error drawing code, so the (2, N) rule doesn’t change.
Want each city in its own shade? Pass a list to color, as in Matplotlib bars with different colors.
Method 3: Draw horizontal asymmetric error bars with xerr
Use this when city names are long or the ranges read better left to right. Same data, axes swapped:
import matplotlib.pyplot as plt
from hotel_rates import cities, median, lower, upper
fig, ax = plt.subplots(figsize=(7, 4), layout="constrained")
ax.errorbar(median, cities, xerr=[lower, upper], fmt="s", color="#1F3A5F",
ecolor="#D1495B", elinewidth=2, capsize=5, capthick=2)
ax.set_xlabel("Rate (USD)")
ax.invert_yaxis()
plt.show()

How does this code work? xerr follows the same lower-then-upper order, where lower means left. ecolor, elinewidth and capthick style only the error bars, and invert_yaxis() puts Austin on top.
To add a reference line such as a budget cap, see a horizontal line on an errorbar plot.
Why does errorbar() say yerr must not contain negative values?
You’ve subtracted in the wrong order. Same data, with lower flipped:
import matplotlib.pyplot as plt
from hotel_rates import cities, median, low, upper
lower = low - median # backwards: gives negative values
fig, ax = plt.subplots()
ax.errorbar(cities, median, yerr=[lower, upper], fmt="o")
Output:
Traceback (most recent call last):
File "C:\pyguides\negative_error.py", line 6, in <module>
ax.errorbar(cities, median, yerr=[lower, upper], fmt="o")
File "C:\pyguides\venv\Lib\site-packages\matplotlib\_api\deprecation.py", line 477, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "C:\pyguides\venv\Lib\site-packages\matplotlib\__init__.py", line 1531, in inner
return func(
^^^^^
File "C:\pyguides\venv\Lib\site-packages\matplotlib\axes\_axes.py", line 4232, in errorbar
raise ValueError(
ValueError: 'yerr' must not contain negative values

The fix is median - low and high - median. The silent version is worse: passing raw bounds as yerr=[low, high] raises nothing, yet Austin’s bar runs from 37.25 to 458.25.
How do you plot one asymmetric error bar for a single point?
Wrap each value in its own list. With one point, a flat two-item list fails because Matplotlib can’t match it to one y value. Here’s Seattle alone:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
try:
ax.errorbar([0], [221.25], yerr=[37.50, 90.75])
except ValueError as err:
print("flat list failed:", type(err).__name__)
bars = ax.errorbar([0], [221.25], yerr=[[37.50], [90.75]])
segment = bars.lines[2][0].get_segments()[0]
print("bar runs from", [float(p[1]) for p in segment])
Output:
flat list failed: ValueError
bar runs from [183.75, 312.0]
The nested form draws from 183.75 to 312.0, matching the full chart.
Which asymmetric error bar method should you use?
| Goal | Use |
|---|---|
| Points or lines | errorbar(yerr=...) |
| Report-style bars | bar(yerr=...) |
| Long labels | errorbar(xerr=...) |
Things to Keep in Mind
- Save with
fig.savefig()beforeplt.show(), or you may get a blank saved image. - Spanning several orders of magnitude? A Matplotlib log-log plot keeps long bars readable.
These Matplotlib guides are good next stops once your error bars look right:
Frequently asked questions
How do I plot asymmetric error bars in Matplotlib?
Pass yerr=[lower, upper] to errorbar(), with both arrays holding distances from each point.
What shape should asymmetric yerr have?
Use shape (2, N): the first row is the distance below each point and the second is the distance above.
Are yerr values absolute limits?
No. They’re offsets, so compute y - low and high - y first.
Can I use asymmetric errors on a bar chart?
Yes. ax.bar() and ax.barh() accept the same two-row format.
How do I remove the line between error bar points?
Pass fmt="o" for markers only, or fmt="none" to draw just the bars.
Where is errorbar documented?
See Axes.errorbar in the Matplotlib docs.
