From 977bff2221278df95979edcea1651e819b63b998 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Fri, 15 Oct 2021 02:38:46 +0200 Subject: [PATCH] Simplify wording of allowed errorbar() error values --- lib/matplotlib/axes/_axes.py | 9 +++++---- lib/matplotlib/tests/test_axes.py | 16 +++++++++------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 719866bbf935..91badadf088e 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3181,7 +3181,7 @@ def errorbar(self, x, y, yerr=None, xerr=None, errors. - *None*: No errorbar. - Note that all error arrays should have *non-negative* values. + All values must be >= 0. See :doc:`/gallery/statistics/errorbar_features` for an example on the usage of ``xerr`` and ``yerr``. @@ -3293,9 +3293,10 @@ def has_negative_values(array): except TypeError: # if array contains 'datetime.timedelta' types return np.any(array < timedelta(0)) - if has_negative_values(xerr) or has_negative_values(yerr): - raise ValueError( - "'xerr' and 'yerr' must have non-negative values") + if has_negative_values(xerr): + raise ValueError("'xerr' must not contain negative values") + if has_negative_values(yerr): + raise ValueError("'yerr' must not contain negative values") if isinstance(errorevery, Integral): errorevery = (0, errorevery) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index cb3d79358695..1b349b2a9c31 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3514,18 +3514,20 @@ def test_errorbar_every_invalid(): ax.errorbar(x, y, yerr, errorevery='foobar') -def test_xerr_yerr_positive(): +def test_xerr_yerr_not_negative(): ax = plt.figure().subplots() - error_message = "'xerr' and 'yerr' must have non-negative values" - - with pytest.raises(ValueError, match=error_message): + with pytest.raises(ValueError, + match="'xerr' must not contain negative values"): ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]], yerr=[[-0.5], [1]]) - with pytest.raises(ValueError, match=error_message): + with pytest.raises(ValueError, + match="'xerr' must not contain negative values"): ax.errorbar(x=[0], y=[0], xerr=[[-0.5], [1]]) - with pytest.raises(ValueError, match=error_message): + with pytest.raises(ValueError, + match="'yerr' must not contain negative values"): ax.errorbar(x=[0], y=[0], yerr=[[-0.5], [1]]) - with pytest.raises(ValueError, match=error_message): + with pytest.raises(ValueError, + match="'yerr' must not contain negative values"): x = np.arange(5) y = [datetime.datetime(2021, 9, i * 2 + 1) for i in x] ax.errorbar(x=x,