@@ -3108,41 +3108,28 @@ def xywhere(xs, ys, mask):
31083108 return xs , ys
31093109
31103110 def extract_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- if np .iterable (a ) and np .iterable (b ):
3126- # using list comps rather than arrays to preserve units
3127- low = [thisx - thiserr for thisx , thiserr
3128- in cbook .safezip (data , a )]
3129- high = [thisx + thiserr for thisx , thiserr
3130- in cbook .safezip (data , b )]
3131- return low , 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- if len (err ) > 1 :
3137- fe = cbook .safe_first_element (err )
3138- if len (err ) != len (data ) or np .size (fe ) > 1 :
3139- raise ValueError ("err must be [ scalar | N, Nx1 "
3140- "or 2xN array-like ]" )
3141- # using list comps rather than arrays to preserve units
3142- low = [thisx - thiserr for thisx , thiserr
3143- in cbook .safezip (data , err )]
3144- high = [thisx + thiserr for thisx , thiserr
3145- in cbook .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+ a_sh = np .shape (a )
3125+ b_sh = np .shape (b )
3126+ if (len (a_sh ) > 2 or (len (a_sh ) == 2 and a_sh [1 ] != 1 )
3127+ or len (b_sh ) > 2 or (len (b_sh ) == 2 and b_sh [1 ] != 1 )):
3128+ raise ValueError (
3129+ "err must be a scalar or a 1D or (2, n) array-like" )
3130+ # Using list comprehensions rather than arrays to preserve units.
3131+ low = [v - e for v , e in cbook .safezip (data , a )]
3132+ high = [v + e for v , e in cbook .safezip (data , b )]
31463133 return low , high
31473134
31483135 if xerr is not None :
0 commit comments