Skip to content

Commit 4e16a84

Browse files
committed
Fix unit handling in errorbar for astropy.
Unfortunately, this bug only triggers with astropy's unit implementation, but not with either of matplotlib's "test" units (testing.jpl_units and test_units.Quantity). So I don't have a self-contained way to add a test...
1 parent dca4a97 commit 4e16a84

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,13 +3427,17 @@ def extract_err(name, err, data, lolims, uplims):
34273427
the note in the main docstring about this parameter's name.
34283428
"""
34293429
try:
3430-
low, high = np.broadcast_to(err, (2, len(data)))
3430+
np.broadcast_to(err, (2, len(data)))
34313431
except ValueError:
34323432
raise ValueError(
34333433
f"'{name}err' (shape: {np.shape(err)}) must be a scalar "
34343434
f"or a 1D or (2, n) array-like whose shape matches "
34353435
f"'{name}' (shape: {np.shape(data)})") from None
3436-
return data - low * ~lolims, data + high * ~uplims # low, high
3436+
# This is like
3437+
# low, high = np.broadcast_to(...)
3438+
# return data - low * ~lolims, data + high * ~uplims
3439+
# except that broadcast_to would strip units.
3440+
return data + np.row_stack([-(1 - lolims), 1 - uplims]) * err
34373441

34383442
if xerr is not None:
34393443
left, right = extract_err('x', xerr, x, xlolims, xuplims)

0 commit comments

Comments
 (0)