Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: ensure that errorbar does not error on masked negative errors.#29897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 3 commits intomatplotlib:mainfrommhvk:allow_masked_negative_errors
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletionslib/matplotlib/axes/_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3756,9 +3756,12 @@ def apply_mask(arrays, mask):
f"'{dep_axis}err' must not contain None. "
"Use NaN if you want to skip a value.")

res = np.zeros(err.shape, dtype=bool) # Default in case of nan
if np.any(np.less(err, -err, out=res, where=(err == err))):
# like err<0, but also works for timedelta and nan.
# Raise if any errors are negative, but not if they are nan.
# To avoid nan comparisons (which lead to warnings on some
# platforms), we select with `err==err` (which is False for nan).
# Also, since datetime.timedelta cannot be compared with 0,
# we compare with the negative error instead.
if np.any((check := err[err == err]) < -check):
raise ValueError(
f"'{dep_axis}err' must not contain negative values")
# This is like
Expand Down
19 changes: 16 additions & 3 deletionslib/matplotlib/tests/test_axes.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4532,10 +4532,23 @@ def test_errorbar_nan(fig_test, fig_ref):
xs = range(5)
ys = np.array([1, 2, np.nan, np.nan, 3])
es = np.array([4, 5, np.nan, np.nan, 6])
ax.errorbar(xs, ys, es)
ax.errorbar(xs, ys,yerr=es)
ax = fig_ref.add_subplot()
ax.errorbar([0, 1], [1, 2], [4, 5])
ax.errorbar([4], [3], [6], fmt="C0")
ax.errorbar([0, 1], [1, 2], yerr=[4, 5])
ax.errorbar([4], [3], yerr=[6], fmt="C0")


@check_figures_equal()
def test_errorbar_masked_negative(fig_test, fig_ref):
ax = fig_test.add_subplot()
xs = range(5)
mask = np.array([False, False, True, True, False])
ys = np.ma.array([1, 2, 2, 2, 3], mask=mask)
es = np.ma.array([4, 5, -1, -10, 6], mask=mask)
ax.errorbar(xs, ys, yerr=es)
ax = fig_ref.add_subplot()
ax.errorbar([0, 1], [1, 2], yerr=[4, 5])
ax.errorbar([4], [3], yerr=[6], fmt="C0")


@image_comparison(['hist_stacked_stepfilled.png', 'hist_stacked_stepfilled.png'])
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp