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

Commitd91d216

Browse files
committed
BUG: ensure that errorbar does not error on masked negative errors.
errorbar checks that errors are not negative, but a bit convolutedly,in order to avoid triggering on nan. Unfortunately, the work-aroundfor nan means that possible masks get discarded, and hence passing ina masked error array that has a negative but masked value leads toan exception. This PR solves that by simply combining the test fornegative values with the indirect isnan test (err == err), so thatif a masked array is passed, the test values are masked and ignoredin the check.As a bonus, this also means that astropy's ``Masked`` arrays can nowbe used -- those refuse to write output of tests to unmasked valuessince that would discard the mask (which is indeed the underlyingproblem here).
1 parentd55bdde commitd91d216

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

‎lib/matplotlib/axes/_axes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3756,8 +3756,7 @@ def apply_mask(arrays, mask):
37563756
f"'{dep_axis}err' must not contain None. "
37573757
"Use NaN if you want to skip a value.")
37583758

3759-
res=np.zeros(err.shape,dtype=bool)# Default in case of nan
3760-
ifnp.any(np.less(err,-err,out=res,where=(err==err))):
3759+
ifnp.any((err<-err)& (err==err)):
37613760
# like err<0, but also works for timedelta and nan.
37623761
raiseValueError(
37633762
f"'{dep_axis}err' must not contain negative values")

‎lib/matplotlib/tests/test_axes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4538,6 +4538,19 @@ def test_errorbar_nan(fig_test, fig_ref):
45384538
ax.errorbar([4], [3], [6],fmt="C0")
45394539

45404540

4541+
@check_figures_equal()
4542+
deftest_errorbar_masked_negative(fig_test,fig_ref):
4543+
ax=fig_test.add_subplot()
4544+
xs=range(5)
4545+
mask=np.array([False,False,True,True,False])
4546+
ys=np.ma.array([1,2,2,2,3],mask=mask)
4547+
es=np.ma.array([4,5,-1,-10,6],mask=mask)
4548+
ax.errorbar(xs,ys,es)
4549+
ax=fig_ref.add_subplot()
4550+
ax.errorbar([0,1], [1,2], [4,5])
4551+
ax.errorbar([4], [3], [6],fmt="C0")
4552+
4553+
45414554
@image_comparison(['hist_stacked_stepfilled.png','hist_stacked_stepfilled.png'])
45424555
deftest_hist_stacked_stepfilled():
45434556
# make some data

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp