@@ -708,10 +708,8 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
708
708
"argument; axhline generates its own transform." )
709
709
ymin , ymax = self .get_ybound ()
710
710
711
- # We need to strip away the units for comparison with
712
- # non-unitized bounds
713
- self ._process_unit_info (ydata = y , kwargs = kwargs )
714
- yy = self .convert_yunits (y )
711
+ # Strip away the units for comparison with non-unitized bounds.
712
+ yy , = self ._process_unit_info ([("y" , y )], kwargs )
715
713
scaley = (yy < ymin ) or (yy > ymax )
716
714
717
715
trans = self .get_yaxis_transform (which = 'grid' )
@@ -777,10 +775,8 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
777
775
"argument; axvline generates its own transform." )
778
776
xmin , xmax = self .get_xbound ()
779
777
780
- # We need to strip away the units for comparison with
781
- # non-unitized bounds
782
- self ._process_unit_info (xdata = x , kwargs = kwargs )
783
- xx = self .convert_xunits (x )
778
+ # Strip away the units for comparison with non-unitized bounds.
779
+ xx , = self ._process_unit_info ([("x" , x )], kwargs )
784
780
scalex = (xx < xmin ) or (xx > xmax )
785
781
786
782
trans = self .get_xaxis_transform (which = 'grid' )
@@ -917,19 +913,13 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
917
913
--------
918
914
axvspan : Add a vertical span across the axes.
919
915
"""
916
+ # Strip units away.
920
917
self ._check_no_units ([xmin , xmax ], ['xmin' , 'xmax' ])
921
- trans = self .get_yaxis_transform (which = 'grid' )
922
-
923
- # process the unit information
924
- self ._process_unit_info ([xmin , xmax ], [ymin , ymax ], kwargs = kwargs )
925
-
926
- # first we need to strip away the units
927
- xmin , xmax = self .convert_xunits ([xmin , xmax ])
928
- ymin , ymax = self .convert_yunits ([ymin , ymax ])
918
+ (ymin , ymax ), = self ._process_unit_info ([("y" , [ymin , ymax ])], kwargs )
929
919
930
920
verts = (xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )
931
921
p = mpatches .Polygon (verts , ** kwargs )
932
- p .set_transform (trans )
922
+ p .set_transform (self . get_yaxis_transform ( which = "grid" ) )
933
923
self .add_patch (p )
934
924
self ._request_autoscale_view (scalex = False )
935
925
return p
@@ -978,19 +968,13 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
978
968
>>> axvspan(1.25, 1.55, facecolor='g', alpha=0.5)
979
969
980
970
"""
971
+ # Strip units away.
981
972
self ._check_no_units ([ymin , ymax ], ['ymin' , 'ymax' ])
982
- trans = self .get_xaxis_transform (which = 'grid' )
983
-
984
- # process the unit information
985
- self ._process_unit_info ([xmin , xmax ], [ymin , ymax ], kwargs = kwargs )
986
-
987
- # first we need to strip away the units
988
- xmin , xmax = self .convert_xunits ([xmin , xmax ])
989
- ymin , ymax = self .convert_yunits ([ymin , ymax ])
973
+ (xmin , xmax ), = self ._process_unit_info ([("x" , [xmin , xmax ])], kwargs )
990
974
991
975
verts = [(xmin , ymin ), (xmin , ymax ), (xmax , ymax ), (xmax , ymin )]
992
976
p = mpatches .Polygon (verts , ** kwargs )
993
- p .set_transform (trans )
977
+ p .set_transform (self . get_xaxis_transform ( which = "grid" ) )
994
978
self .add_patch (p )
995
979
self ._request_autoscale_view (scaley = False )
996
980
return p
@@ -1032,11 +1016,8 @@ def hlines(self, y, xmin, xmax, colors=None, linestyles='solid',
1032
1016
"""
1033
1017
1034
1018
# We do the conversion first since not all unitized data is uniform
1035
- # process the unit information
1036
- self ._process_unit_info ([xmin , xmax ], y , kwargs = kwargs )
1037
- y = self .convert_yunits (y )
1038
- xmin = self .convert_xunits (xmin )
1039
- xmax = self .convert_xunits (xmax )
1019
+ xmin , xmax , y = self ._process_unit_info (
1020
+ [("x" , xmin ), ("x" , xmax ), ("y" , y )], kwargs )
1040
1021
1041
1022
if not np .iterable (y ):
1042
1023
y = [y ]
@@ -1111,12 +1092,9 @@ def vlines(self, x, ymin, ymax, colors=None, linestyles='solid',
1111
1092
axvline: vertical line across the axes
1112
1093
"""
1113
1094
1114
- self ._process_unit_info (xdata = x , ydata = [ymin , ymax ], kwargs = kwargs )
1115
-
1116
1095
# We do the conversion first since not all unitized data is uniform
1117
- x = self .convert_xunits (x )
1118
- ymin = self .convert_yunits (ymin )
1119
- ymax = self .convert_yunits (ymax )
1096
+ x , ymin , ymax = self ._process_unit_info (
1097
+ [("x" , x ), ("y" , ymin ), ("y" , ymax )], kwargs )
1120
1098
1121
1099
if not np .iterable (x ):
1122
1100
x = [x ]
@@ -1254,14 +1232,9 @@ def eventplot(self, positions, orientation='horizontal', lineoffsets=1,
1254
1232
--------
1255
1233
.. plot:: gallery/lines_bars_and_markers/eventplot_demo.py
1256
1234
"""
1257
- self ._process_unit_info (xdata = positions ,
1258
- ydata = [lineoffsets , linelengths ],
1259
- kwargs = kwargs )
1260
-
1261
1235
# We do the conversion first since not all unitized data is uniform
1262
- positions = self .convert_xunits (positions )
1263
- lineoffsets = self .convert_yunits (lineoffsets )
1264
- linelengths = self .convert_yunits (linelengths )
1236
+ positions , lineoffsets , linelengths = self ._process_unit_info (
1237
+ [("x" , positions ), ("y" , lineoffsets ), ("y" , linelengths )], kwargs )
1265
1238
1266
1239
if not np .iterable (positions ):
1267
1240
positions = [positions ]
@@ -2283,11 +2256,13 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
2283
2256
x = 0
2284
2257
2285
2258
if orientation == 'vertical' :
2286
- self ._process_unit_info (xdata = x , ydata = height , kwargs = kwargs )
2259
+ self ._process_unit_info (
2260
+ [("x" , x ), ("y" , height )], kwargs , convert = False )
2287
2261
if log :
2288
2262
self .set_yscale ('log' , nonpositive = 'clip' )
2289
2263
elif orientation == 'horizontal' :
2290
- self ._process_unit_info (xdata = width , ydata = y , kwargs = kwargs )
2264
+ self ._process_unit_info (
2265
+ [("x" , width ), ("y" , y )], kwargs , convert = False )
2291
2266
if log :
2292
2267
self .set_xscale ('log' , nonpositive = 'clip' )
2293
2268
@@ -2567,9 +2542,8 @@ def broken_barh(self, xranges, yrange, **kwargs):
2567
2542
ydata = cbook .safe_first_element (yrange )
2568
2543
else :
2569
2544
ydata = None
2570
- self ._process_unit_info (xdata = xdata ,
2571
- ydata = ydata ,
2572
- kwargs = kwargs )
2545
+ self ._process_unit_info (
2546
+ [("x" , xdata ), ("y" , ydata )], kwargs , convert = False )
2573
2547
xranges_conv = []
2574
2548
for xr in xranges :
2575
2549
if len (xr ) != 2 :
@@ -2689,13 +2663,9 @@ def stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0,
2689
2663
locs , heads , * args = args
2690
2664
2691
2665
if orientation == 'vertical' :
2692
- self ._process_unit_info (xdata = locs , ydata = heads )
2693
- locs = self .convert_xunits (locs )
2694
- heads = self .convert_yunits (heads )
2666
+ locs , heads = self ._process_unit_info ([("x" , locs ), ("y" , heads )])
2695
2667
else :
2696
- self ._process_unit_info (xdata = heads , ydata = locs )
2697
- heads = self .convert_xunits (heads )
2698
- locs = self .convert_yunits (locs )
2668
+ heads , locs = self ._process_unit_info ([("x" , heads ), ("y" , locs )])
2699
2669
2700
2670
# defaults for formats
2701
2671
if linefmt is None :
@@ -3179,7 +3149,7 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3179
3149
if int (offset ) != offset :
3180
3150
raise ValueError ("errorevery's starting index must be an integer" )
3181
3151
3182
- self ._process_unit_info (xdata = x , ydata = y , kwargs = kwargs )
3152
+ self ._process_unit_info ([( "x" , x ), ( "y" , y )], kwargs , convert = False )
3183
3153
3184
3154
# Make sure all the args are iterable; use lists not arrays to preserve
3185
3155
# units.
@@ -4346,9 +4316,7 @@ def scatter(self, x, y, s=None, c=None, marker=None, cmap=None, norm=None,
4346
4316
"""
4347
4317
# Process **kwargs to handle aliases, conflicts with explicit kwargs:
4348
4318
4349
- self ._process_unit_info (xdata = x , ydata = y , kwargs = kwargs )
4350
- x = self .convert_xunits (x )
4351
- y = self .convert_yunits (y )
4319
+ x , y = self ._process_unit_info ([("x" , x ), ("y" , y )], kwargs )
4352
4320
4353
4321
# np.ma.ravel yields an ndarray, not a masked array,
4354
4322
# unless its argument is a masked array.
@@ -4577,7 +4545,7 @@ def reduce_C_function(C: array) -> float
4577
4545
%(PolyCollection)s
4578
4546
4579
4547
"""
4580
- self ._process_unit_info (xdata = x , ydata = y , kwargs = kwargs )
4548
+ self ._process_unit_info ([( "x" , x ), ( "y" , y )], kwargs , convert = False )
4581
4549
4582
4550
x , y , C = cbook .delete_masked_points (x , y , C )
4583
4551
@@ -4926,9 +4894,7 @@ def quiverkey(self, Q, X, Y, U, label, **kw):
4926
4894
def _quiver_units (self , args , kw ):
4927
4895
if len (args ) > 3 :
4928
4896
x , y = args [0 :2 ]
4929
- self ._process_unit_info (xdata = x , ydata = y , kwargs = kw )
4930
- x = self .convert_xunits (x )
4931
- y = self .convert_yunits (y )
4897
+ x , y = self ._process_unit_info ([("x" , x ), ("y" , y )], kw )
4932
4898
return (x , y ) + args [2 :]
4933
4899
return args
4934
4900
@@ -5114,17 +5080,9 @@ def _fill_between_x_or_y(
5114
5080
self ._get_patches_for_fill .get_next_color ()
5115
5081
5116
5082
# Handle united data, such as dates
5117
- self ._process_unit_info (
5118
- ** {f"{ ind_dir } data" : ind , f"{ dep_dir } data" : dep1 }, kwargs = kwargs )
5119
- self ._process_unit_info (
5120
- ** {f"{ dep_dir } data" : dep2 })
5121
-
5122
- # Convert the arrays so we can work with them
5123
- ind = ma .masked_invalid (getattr (self , f"convert_{ ind_dir } units" )(ind ))
5124
- dep1 = ma .masked_invalid (
5125
- getattr (self , f"convert_{ dep_dir } units" )(dep1 ))
5126
- dep2 = ma .masked_invalid (
5127
- getattr (self , f"convert_{ dep_dir } units" )(dep2 ))
5083
+ ind , dep1 , dep2 = map (
5084
+ ma .masked_invalid , self ._process_unit_info (
5085
+ [(ind_dir , ind ), (dep_dir , dep1 ), (dep_dir , dep2 )], kwargs ))
5128
5086
5129
5087
for name , array in [
5130
5088
(ind_dir , ind ), (f"{ dep_dir } 1" , dep1 ), (f"{ dep_dir } 2" , dep2 )]:
@@ -5739,9 +5697,7 @@ def pcolor(self, *args, shading=None, alpha=None, norm=None, cmap=None,
5739
5697
Ny , Nx = X .shape
5740
5698
5741
5699
# unit conversion allows e.g. datetime objects as axis values
5742
- self ._process_unit_info (xdata = X , ydata = Y , kwargs = kwargs )
5743
- X = self .convert_xunits (X )
5744
- Y = self .convert_yunits (Y )
5700
+ X , Y = self ._process_unit_info ([("x" , X ), ("y" , Y )], kwargs )
5745
5701
5746
5702
# convert to MA, if necessary.
5747
5703
C = ma .asarray (C )
@@ -6016,9 +5972,7 @@ def pcolormesh(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
6016
5972
X = X .ravel ()
6017
5973
Y = Y .ravel ()
6018
5974
# unit conversion allows e.g. datetime objects as axis values
6019
- self ._process_unit_info (xdata = X , ydata = Y , kwargs = kwargs )
6020
- X = self .convert_xunits (X )
6021
- Y = self .convert_yunits (Y )
5975
+ X , Y = self ._process_unit_info ([("x" , X ), ("y" , Y )], kwargs )
6022
5976
6023
5977
# convert to one dimensional arrays
6024
5978
C = C .ravel ()
@@ -6497,16 +6451,23 @@ def hist(self, x, bins=None, range=None, density=False, weights=None,
6497
6451
x = cbook ._reshape_2D (x , 'x' )
6498
6452
nx = len (x ) # number of datasets
6499
6453
6500
- # Process unit information
6501
- # Unit conversion is done individually on each dataset
6502
- self ._process_unit_info (xdata = x [0 ], kwargs = kwargs )
6503
- x = [self .convert_xunits (xi ) for xi in x ]
6454
+ # Process unit information. _process_unit_info sets the unit and
6455
+ # converts the first dataset; then we convert each following dataset
6456
+ # one at a time.
6457
+ if orientation == "vertical" :
6458
+ convert_units = self .convert_xunits
6459
+ x = [* self ._process_unit_info ([("x" , x [0 ])], kwargs ),
6460
+ * map (convert_units , x [1 :])]
6461
+ else : # horizontal
6462
+ convert_units = self .convert_yunits
6463
+ x = [* self ._process_unit_info ([("y" , x [0 ])], kwargs ),
6464
+ * map (convert_units , x [1 :])]
6504
6465
6505
6466
if bin_range is not None :
6506
- bin_range = self . convert_xunits (bin_range )
6467
+ bin_range = convert_units (bin_range )
6507
6468
6508
6469
if not cbook .is_scalar_or_string (bins ):
6509
- bins = self . convert_xunits (bins )
6470
+ bins = convert_units (bins )
6510
6471
6511
6472
# We need to do to 'weights' what was done to 'x'
6512
6473
if weights is not None :
@@ -6787,9 +6748,8 @@ def stairs(self, values, edges=None, *,
6787
6748
if edges is None :
6788
6749
edges = np .arange (len (values ) + 1 )
6789
6750
6790
- self ._process_unit_info (xdata = edges , ydata = values , kwargs = kwargs )
6791
- edges = self .convert_xunits (edges )
6792
- values = self .convert_yunits (values )
6751
+ edges , values = self ._process_unit_info (
6752
+ [("x" , edges ), ("y" , values )], kwargs )
6793
6753
6794
6754
patch = mpatches .StepPatch (values ,
6795
6755
edges ,
0 commit comments