@@ -3281,27 +3281,12 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3281
3281
kwargs = {k : v for k , v in kwargs .items () if v is not None }
3282
3282
kwargs .setdefault ('zorder' , 2 )
3283
3283
3284
- self ._process_unit_info ([("x" , x ), ("y" , y )], kwargs , convert = False )
3285
-
3286
- # Make sure all the args are iterable; use lists not arrays to preserve
3287
- # units.
3288
- if not np .iterable (x ):
3289
- x = [x ]
3290
-
3291
- if not np .iterable (y ):
3292
- y = [y ]
3293
-
3284
+ x , y , xerr , yerr = self ._process_unit_info (
3285
+ [("x" , x ), ("y" , y ), ("x" , xerr ), ("y" , yerr )], kwargs )
3286
+ x , y = np .atleast_1d (x , y ) # Make sure all the args are iterable.
3294
3287
if len (x ) != len (y ):
3295
3288
raise ValueError ("'x' and 'y' must have the same size" )
3296
3289
3297
- if xerr is not None :
3298
- if not np .iterable (xerr ):
3299
- xerr = [xerr ] * len (x )
3300
-
3301
- if yerr is not None :
3302
- if not np .iterable (yerr ):
3303
- yerr = [yerr ] * len (y )
3304
-
3305
3290
if isinstance (errorevery , Integral ):
3306
3291
errorevery = (0 , errorevery )
3307
3292
if isinstance (errorevery , tuple ):
@@ -3313,10 +3298,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3313
3298
raise ValueError (
3314
3299
f'errorevery={ errorevery !r} is a not a tuple of two '
3315
3300
f'integers' )
3316
-
3317
3301
elif isinstance (errorevery , slice ):
3318
3302
pass
3319
-
3320
3303
elif not isinstance (errorevery , str ) and np .iterable (errorevery ):
3321
3304
# fancy indexing
3322
3305
try :
@@ -3328,6 +3311,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3328
3311
else :
3329
3312
raise ValueError (
3330
3313
f"errorevery={ errorevery !r} is not a recognized value" )
3314
+ everymask = np .zeros (len (x ), bool )
3315
+ everymask [errorevery ] = True
3331
3316
3332
3317
label = kwargs .pop ("label" , None )
3333
3318
kwargs ['label' ] = '_nolegend_'
@@ -3410,13 +3395,8 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3410
3395
xlolims = np .broadcast_to (xlolims , len (x )).astype (bool )
3411
3396
xuplims = np .broadcast_to (xuplims , len (x )).astype (bool )
3412
3397
3413
- everymask = np .zeros (len (x ), bool )
3414
- everymask [errorevery ] = True
3415
-
3416
- def apply_mask (arrays , mask ):
3417
- # Return, for each array in *arrays*, the elements for which *mask*
3418
- # is True, without using fancy indexing.
3419
- return [[* itertools .compress (array , mask )] for array in arrays ]
3398
+ # Vectorized fancy-indexer.
3399
+ def apply_mask (arrays , mask ): return [array [mask ] for array in arrays ]
3420
3400
3421
3401
def extract_err (name , err , data , lolims , uplims ):
3422
3402
"""
@@ -3437,24 +3417,14 @@ def extract_err(name, err, data, lolims, uplims):
3437
3417
Error is only applied on **lower** side when this is True. See
3438
3418
the note in the main docstring about this parameter's name.
3439
3419
"""
3440
- try : # Asymmetric error: pair of 1D iterables.
3441
- a , b = err
3442
- iter (a )
3443
- iter (b )
3444
- except (TypeError , ValueError ):
3445
- a = b = err # Symmetric error: 1D iterable.
3446
- if np .ndim (a ) > 1 or np .ndim (b ) > 1 :
3420
+ try :
3421
+ low , high = np .broadcast_to (err , (2 , len (data )))
3422
+ except ValueError :
3447
3423
raise ValueError (
3448
- f"{ name } err must be a scalar or a 1D or (2, n) array-like" )
3449
- # Using list comprehensions rather than arrays to preserve units.
3450
- for e in [a , b ]:
3451
- if len (data ) != len (e ):
3452
- raise ValueError (
3453
- f"The lengths of the data ({ len (data )} ) and the "
3454
- f"error { len (e )} do not match" )
3455
- low = [v if lo else v - e for v , e , lo in zip (data , a , lolims )]
3456
- high = [v if up else v + e for v , e , up in zip (data , b , uplims )]
3457
- return low , high
3424
+ f"'{ name } err' (shape: { np .shape (err )} ) must be a scalar "
3425
+ f"or a 1D or (2, n) array-like whose shape matches "
3426
+ f"'{ name } ' (shape: { np .shape (data )} )" ) from None
3427
+ return data - low * ~ lolims , data + high * ~ uplims # low, high
3458
3428
3459
3429
if xerr is not None :
3460
3430
left , right = extract_err ('x' , xerr , x , xlolims , xuplims )
0 commit comments