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

Commit7f4b044

Browse files
authored
Merge pull request#13124 from anntzer/errorbar
Simplify parsing of errorbar input.
2 parentsc9ed617 +a2595e0 commit7f4b044

File tree

1 file changed

+20
-33
lines changed

1 file changed

+20
-33
lines changed

‎lib/matplotlib/axes/_axes.py‎

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3180,41 +3180,28 @@ def xywhere(xs, ys, mask):
31803180
returnxs,ys
31813181

31823182
defextract_err(err,data):
3183-
'''private function to compute error bars
3184-
3185-
Parameters
3186-
----------
3187-
err : iterable
3188-
xerr or yerr from errorbar
3189-
data : iterable
3190-
x or y from errorbar
3191-
'''
3192-
try:
3183+
"""
3184+
Private function to parse *err* and subtract/add it to *data*.
3185+
3186+
Both *err* and *data* are already iterables at this point.
3187+
"""
3188+
try:# Asymmetric error: pair of 1D iterables.
31933189
a,b=err
3190+
iter(a)
3191+
iter(b)
31943192
except (TypeError,ValueError):
3195-
pass
3196-
else:
3197-
ifnp.iterable(a)andnp.iterable(b):
3198-
# using list comps rather than arrays to preserve units
3199-
low= [thisx-thiserrforthisx,thiserr
3200-
incbook.safezip(data,a)]
3201-
high= [thisx+thiserrforthisx,thiserr
3202-
incbook.safezip(data,b)]
3203-
returnlow,high
3204-
# Check if xerr is scalar or symmetric. Asymmetric is handled
3205-
# above. This prevents Nx2 arrays from accidentally
3206-
# being accepted, when the user meant the 2xN transpose.
3207-
# special case for empty lists
3208-
iflen(err)>1:
3209-
fe=cbook.safe_first_element(err)
3210-
iflen(err)!=len(data)ornp.size(fe)>1:
3211-
raiseValueError("err must be [ scalar | N, Nx1 "
3212-
"or 2xN array-like ]")
3213-
# using list comps rather than arrays to preserve units
3214-
low= [thisx-thiserrforthisx,thiserr
3215-
incbook.safezip(data,err)]
3216-
high= [thisx+thiserrforthisx,thiserr
3217-
incbook.safezip(data,err)]
3193+
a=b=err# Symmetric error: 1D iterable.
3194+
# This could just be `np.ndim(a) > 1 and np.ndim(b) > 1`, except
3195+
# for the (undocumented, but tested) support for (n, 1) arrays.
3196+
a_sh=np.shape(a)
3197+
b_sh=np.shape(b)
3198+
if (len(a_sh)>2or (len(a_sh)==2anda_sh[1]!=1)
3199+
orlen(b_sh)>2or (len(b_sh)==2andb_sh[1]!=1)):
3200+
raiseValueError(
3201+
"err must be a scalar or a 1D or (2, n) array-like")
3202+
# Using list comprehensions rather than arrays to preserve units.
3203+
low= [v-eforv,eincbook.safezip(data,a)]
3204+
high= [v+eforv,eincbook.safezip(data,b)]
32183205
returnlow,high
32193206

32203207
ifxerrisnotNone:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp