FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Simplify wording of allowed errorbar() error values by timhoffm · Pull Request #21362 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions lib/matplotlib/axes/_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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``.
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions lib/matplotlib/tests/test_axes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

Back | FazBrowse Home | New Git URL