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

Commit07ad987

Browse files
committed
Simplify parsing of errorbar input.
1 parentde38ef2 commit07ad987

File tree

1 file changed

+19
-33
lines changed

1 file changed

+19
-33
lines changed

‎lib/matplotlib/axes/_axes.py‎

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3108,41 +3108,27 @@ def xywhere(xs, ys, mask):
31083108
returnxs,ys
31093109

31103110
defextract_err(err,data):
3111-
'''private function to compute error bars
3112-
3113-
Parameters
3114-
----------
3115-
err : iterable
3116-
xerr or yerr from errorbar
3117-
data : iterable
3118-
x or y from errorbar
3119-
'''
3120-
try:
3111+
"""
3112+
Private function to parse *err* and subtract/add it to *data*.
3113+
3114+
Both *err* and *data* are already iterables at this point.
3115+
"""
3116+
try:# Asymmetric error: pair of 1D iterables.
31213117
a,b=err
3118+
iter(a)
3119+
iter(b)
31223120
except (TypeError,ValueError):
3123-
pass
3124-
else:
3125-
ifnp.iterable(a)andnp.iterable(b):
3126-
# using list comps rather than arrays to preserve units
3127-
low= [thisx-thiserrforthisx,thiserr
3128-
incbook.safezip(data,a)]
3129-
high= [thisx+thiserrforthisx,thiserr
3130-
incbook.safezip(data,b)]
3131-
returnlow,high
3132-
# Check if xerr is scalar or symmetric. Asymmetric is handled
3133-
# above. This prevents Nx2 arrays from accidentally
3134-
# being accepted, when the user meant the 2xN transpose.
3135-
# special case for empty lists
3136-
iflen(err)>1:
3137-
fe=cbook.safe_first_element(err)
3138-
iflen(err)!=len(data)ornp.size(fe)>1:
3139-
raiseValueError("err must be [ scalar | N, Nx1 "
3140-
"or 2xN array-like ]")
3141-
# using list comps rather than arrays to preserve units
3142-
low= [thisx-thiserrforthisx,thiserr
3143-
incbook.safezip(data,err)]
3144-
high= [thisx+thiserrforthisx,thiserr
3145-
incbook.safezip(data,err)]
3121+
a=b=err# Symmetric error: 1D iterable.
3122+
# This could just be `np.ndim(a) > 1 and np.ndim(b) > 1`, except
3123+
# for the (undocumented, but tested) support for (n, 1) arrays.
3124+
ash,bsh=map(np.shape, [a,b])
3125+
if (len(ash)>2andnot (len(ash)==2andash[1]==1)
3126+
orlen(bsh)>2andnot (len(bsh)==2andbsh[1]==1)):
3127+
raiseValueError(
3128+
"err must be a scalar or a 1D or (2, n) array-like")
3129+
# Using list comprehensions rather than arrays to preserve units.
3130+
low= [v-eforv,eincbook.safezip(data,a)]
3131+
high= [v+eforv,eincbook.safezip(data,b)]
31463132
returnlow,high
31473133

31483134
ifxerrisnotNone:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp