Skip to content

Commit 2a2ee71

Browse files
authored
Merge pull request #21362 from timhoffm/errorbar-note
Simplify wording of allowed errorbar() error values
2 parents f66c626 + d785214 commit 2a2ee71

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

lib/matplotlib/axes/_axes.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -3181,7 +3181,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
31813181
errors.
31823182
- *None*: No errorbar.
31833183
3184-
Note that all error arrays should have *non-negative* values.
3184+
All values must be >= 0.
31853185
31863186
See :doc:`/gallery/statistics/errorbar_features`
31873187
for an example on the usage of ``xerr`` and ``yerr``.
@@ -3293,9 +3293,10 @@ def has_negative_values(array):
32933293
except TypeError: # if array contains 'datetime.timedelta' types
32943294
return np.any(array < timedelta(0))
32953295

3296-
if has_negative_values(xerr) or has_negative_values(yerr):
3297-
raise ValueError(
3298-
"'xerr' and 'yerr' must have non-negative values")
3296+
if has_negative_values(xerr):
3297+
raise ValueError("'xerr' must not contain negative values")
3298+
if has_negative_values(yerr):
3299+
raise ValueError("'yerr' must not contain negative values")
32993300

33003301
if isinstance(errorevery, Integral):
33013302
errorevery = (0, errorevery)

lib/matplotlib/tests/test_axes.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -3514,18 +3514,20 @@ def test_errorbar_every_invalid():
35143514
ax.errorbar(x, y, yerr, errorevery='foobar')
35153515

35163516

3517-
def test_xerr_yerr_positive():
3517+
def test_xerr_yerr_not_negative():
35183518
ax = plt.figure().subplots()
35193519

3520-
error_message = "'xerr' and 'yerr' must have non-negative values"
3521-
3522-
with pytest.raises(ValueError, match=error_message):
3520+
with pytest.raises(ValueError,
3521+
match="'xerr' must not contain negative values"):
35233522
ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]], yerr=[[-0.5], [1]])
3524-
with pytest.raises(ValueError, match=error_message):
3523+
with pytest.raises(ValueError,
3524+
match="'xerr' must not contain negative values"):
35253525
ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]])
3526-
with pytest.raises(ValueError, match=error_message):
3526+
with pytest.raises(ValueError,
3527+
match="'yerr' must not contain negative values"):
35273528
ax.errorbar(x=[0], y=[0], yerr=[[-0.5], [1]])
3528-
with pytest.raises(ValueError, match=error_message):
3529+
with pytest.raises(ValueError,
3530+
match="'yerr' must not contain negative values"):
35293531
x = np.arange(5)
35303532
y = [datetime.datetime(2021, 9, i * 2 + 1) for i in x]
35313533
ax.errorbar(x=x,

0 commit comments

Comments
 (0)