@@ -541,10 +541,23 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
541
541
class _AxesBase (martist .Artist ):
542
542
name = "rectilinear"
543
543
544
- _axis_names = ("x" , "y" ) # See _get_axis_map.
544
+ # axis names are the prefixes for the attributes that contain the
545
+ # respective axis; e.g. 'x' <-> self.xaxis, containing an XAxis.
546
+ # Note that PolarAxes uses these attributes as well, so that we have
547
+ # 'x' <-> self.xaxis, containing a ThetaAxis. In particular we do not
548
+ # have 'theta' in _axis_names.
549
+ # In practice, this is ('x', 'y') for all 2D Axes and ('x', 'y', 'z')
550
+ # for Axes3D.
551
+ _axis_names = ("x" , "y" )
545
552
_shared_axes = {name : cbook .Grouper () for name in _axis_names }
546
553
_twinned_axes = cbook .Grouper ()
547
554
555
+ @property
556
+ def _axis_map (self ):
557
+ """A mapping of axis names, e.g. 'x', to `Axis` instances."""
558
+ return {name : getattr (self , f"{ name } axis" )
559
+ for name in self ._axis_names }
560
+
548
561
def __str__ (self ):
549
562
return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})" .format (
550
563
type (self ).__name__ , self ._position .bounds )
@@ -644,7 +657,7 @@ def __init__(self, fig, rect,
644
657
645
658
self ._internal_update (kwargs )
646
659
647
- for name , axis in self ._get_axis_map () .items ():
660
+ for name , axis in self ._axis_map .items ():
648
661
axis .callbacks ._pickled_cids .add (
649
662
axis .callbacks .connect (
650
663
'units' , self ._unit_change_handler (name )))
@@ -2437,7 +2450,7 @@ def _unit_change_handler(self, axis_name, event=None):
2437
2450
if event is None : # Allow connecting `self._unit_change_handler(name)`
2438
2451
return functools .partial (
2439
2452
self ._unit_change_handler , axis_name , event = object ())
2440
- _api .check_in_list (self ._get_axis_map () , axis_name = axis_name )
2453
+ _api .check_in_list (self ._axis_map , axis_name = axis_name )
2441
2454
for line in self .lines :
2442
2455
line .recache_always ()
2443
2456
self .relim ()
@@ -2503,7 +2516,7 @@ def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True):
2503
2516
----------
2504
2517
datasets : list
2505
2518
List of (axis_name, dataset) pairs (where the axis name is defined
2506
- as in `._get_axis_map `). Individual datasets can also be None
2519
+ as in `._axis_map `). Individual datasets can also be None
2507
2520
(which gets passed through).
2508
2521
kwargs : dict
2509
2522
Other parameters from which unit info (i.e., the *xunits*,
@@ -2525,7 +2538,7 @@ def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True):
2525
2538
# (e.g. if some are scalars, etc.).
2526
2539
datasets = datasets or []
2527
2540
kwargs = kwargs or {}
2528
- axis_map = self ._get_axis_map ()
2541
+ axis_map = self ._axis_map
2529
2542
for axis_name , data in datasets :
2530
2543
try :
2531
2544
axis = axis_map [axis_name ]
@@ -2953,22 +2966,6 @@ def handle_single_axis(scale, autoscaleon, shared_axes, name,
2953
2966
scaley , self ._autoscaleYon , self ._shared_axes ["y" ], 'y' ,
2954
2967
self .yaxis , self ._ymargin , y_stickies , self .set_ybound )
2955
2968
2956
- def _get_axis_list (self ):
2957
- return tuple (getattr (self , f"{ name } axis" ) for name in self ._axis_names )
2958
-
2959
- def _get_axis_map (self ):
2960
- """
2961
- Return a mapping of `Axis` "names" to `Axis` instances.
2962
-
2963
- The `Axis` name is derived from the attribute under which the instance
2964
- is stored, so e.g. for polar Axes, the theta-axis is still named "x"
2965
- and the r-axis is still named "y" (for back-compatibility).
2966
-
2967
- In practice, this means that the entries are typically "x" and "y", and
2968
- additionally "z" for 3D Axes.
2969
- """
2970
- return dict (zip (self ._axis_names , self ._get_axis_list ()))
2971
-
2972
2969
def _update_title_position (self , renderer ):
2973
2970
"""
2974
2971
Update the title position based on the bounding box enclosing
@@ -3069,7 +3066,7 @@ def draw(self, renderer):
3069
3066
self ._update_title_position (renderer )
3070
3067
3071
3068
if not self .axison :
3072
- for _axis in self ._get_axis_list ():
3069
+ for _axis in self ._axis_map . values ():
3073
3070
artists .remove (_axis )
3074
3071
3075
3072
if not self .figure .canvas .is_saving ():
@@ -3131,7 +3128,7 @@ def redraw_in_frame(self):
3131
3128
raise AttributeError ("redraw_in_frame can only be used after an "
3132
3129
"initial draw which caches the renderer" )
3133
3130
with ExitStack () as stack :
3134
- for artist in [* self ._get_axis_list (),
3131
+ for artist in [* self ._axis_map . values (),
3135
3132
self .title , self ._left_title , self ._right_title ]:
3136
3133
stack .enter_context (artist ._cm_set (visible = False ))
3137
3134
self .draw (self .figure ._cachedRenderer )
@@ -3202,7 +3199,7 @@ def set_axisbelow(self, b):
3202
3199
zorder = 1.5
3203
3200
else :
3204
3201
raise ValueError ("Unexpected axisbelow value" )
3205
- for axis in self ._get_axis_list ():
3202
+ for axis in self ._axis_map . values ():
3206
3203
axis .set_zorder (zorder )
3207
3204
self .stale = True
3208
3205
@@ -3306,8 +3303,8 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
3306
3303
) from err
3307
3304
STYLES = {'sci' : True , 'scientific' : True , 'plain' : False , '' : None }
3308
3305
is_sci_style = _api .check_getitem (STYLES , style = style )
3309
- axis_map = {** {k : [v ] for k , v in self ._get_axis_map () .items ()},
3310
- 'both' : self ._get_axis_list ( )}
3306
+ axis_map = {** {k : [v ] for k , v in self ._axis_map .items ()},
3307
+ 'both' : list ( self ._axis_map . values () )}
3311
3308
axises = _api .check_getitem (axis_map , axis = axis )
3312
3309
try :
3313
3310
for axis in axises :
@@ -3361,7 +3358,7 @@ def locator_params(self, axis='both', tight=None, **kwargs):
3361
3358
_api .check_in_list ([* self ._axis_names , "both" ], axis = axis )
3362
3359
for name in self ._axis_names :
3363
3360
if axis in [name , "both" ]:
3364
- loc = self ._get_axis_map () [name ].get_major_locator ()
3361
+ loc = self ._axis_map [name ].get_major_locator ()
3365
3362
loc .set_params (** kwargs )
3366
3363
self ._request_autoscale_view (name , tight = tight )
3367
3364
self .stale = True
@@ -4412,7 +4409,7 @@ def get_children(self):
4412
4409
return [
4413
4410
* self ._children ,
4414
4411
* self .spines .values (),
4415
- * self ._get_axis_list (),
4412
+ * self ._axis_map . values (),
4416
4413
self .title , self ._left_title , self ._right_title ,
4417
4414
* self .child_axes ,
4418
4415
* ([self .legend_ ] if self .legend_ is not None else []),
@@ -4444,10 +4441,10 @@ def get_default_bbox_extra_artists(self):
4444
4441
4445
4442
artists = self .get_children ()
4446
4443
4447
- for _axis in self ._get_axis_list ():
4444
+ for axis in self ._axis_map . values ():
4448
4445
# axis tight bboxes are calculated separately inside
4449
4446
# Axes.get_tightbbox() using for_layout_only=True
4450
- artists .remove (_axis )
4447
+ artists .remove (axis )
4451
4448
if not (self .axison and self ._frameon ):
4452
4449
# don't do bbox on spines if frame not on.
4453
4450
for spine in self .spines .values ():
@@ -4520,7 +4517,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
4520
4517
else :
4521
4518
self .apply_aspect ()
4522
4519
4523
- for axis in self ._get_axis_list ():
4520
+ for axis in self ._axis_map . values ():
4524
4521
if self .axison and axis .get_visible ():
4525
4522
ba = martist ._get_tightbbox_for_layout_only (axis , renderer )
4526
4523
if ba :
0 commit comments