@@ -541,10 +541,23 @@ def _plot_args(self, tup, kwargs, return_kwargs=False):
541541class _AxesBase (martist .Artist ):
542542 name = "rectilinear"
543543
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" )
545552 _shared_axes = {name : cbook .Grouper () for name in _axis_names }
546553 _twinned_axes = cbook .Grouper ()
547554
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+
548561 def __str__ (self ):
549562 return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})" .format (
550563 type (self ).__name__ , self ._position .bounds )
@@ -644,7 +657,7 @@ def __init__(self, fig, rect,
644657
645658 self ._internal_update (kwargs )
646659
647- for name , axis in self ._get_axis_map () .items ():
660+ for name , axis in self ._axis_map .items ():
648661 axis .callbacks ._pickled_cids .add (
649662 axis .callbacks .connect (
650663 'units' , self ._unit_change_handler (name )))
@@ -2437,7 +2450,7 @@ def _unit_change_handler(self, axis_name, event=None):
24372450 if event is None : # Allow connecting `self._unit_change_handler(name)`
24382451 return functools .partial (
24392452 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 )
24412454 for line in self .lines :
24422455 line .recache_always ()
24432456 self .relim ()
@@ -2503,7 +2516,7 @@ def _process_unit_info(self, datasets=None, kwargs=None, *, convert=True):
25032516 ----------
25042517 datasets : list
25052518 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
25072520 (which gets passed through).
25082521 kwargs : dict
25092522 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):
25252538 # (e.g. if some are scalars, etc.).
25262539 datasets = datasets or []
25272540 kwargs = kwargs or {}
2528- axis_map = self ._get_axis_map ()
2541+ axis_map = self ._axis_map
25292542 for axis_name , data in datasets :
25302543 try :
25312544 axis = axis_map [axis_name ]
@@ -2953,22 +2966,6 @@ def handle_single_axis(scale, autoscaleon, shared_axes, name,
29532966 scaley , self ._autoscaleYon , self ._shared_axes ["y" ], 'y' ,
29542967 self .yaxis , self ._ymargin , y_stickies , self .set_ybound )
29552968
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-
29722969 def _update_title_position (self , renderer ):
29732970 """
29742971 Update the title position based on the bounding box enclosing
@@ -3069,7 +3066,7 @@ def draw(self, renderer):
30693066 self ._update_title_position (renderer )
30703067
30713068 if not self .axison :
3072- for _axis in self ._get_axis_list ():
3069+ for _axis in self ._axis_map . values ():
30733070 artists .remove (_axis )
30743071
30753072 if not self .figure .canvas .is_saving ():
@@ -3131,7 +3128,7 @@ def redraw_in_frame(self):
31313128 raise AttributeError ("redraw_in_frame can only be used after an "
31323129 "initial draw which caches the renderer" )
31333130 with ExitStack () as stack :
3134- for artist in [* self ._get_axis_list (),
3131+ for artist in [* self ._axis_map . values (),
31353132 self .title , self ._left_title , self ._right_title ]:
31363133 stack .enter_context (artist ._cm_set (visible = False ))
31373134 self .draw (self .figure ._cachedRenderer )
@@ -3202,7 +3199,7 @@ def set_axisbelow(self, b):
32023199 zorder = 1.5
32033200 else :
32043201 raise ValueError ("Unexpected axisbelow value" )
3205- for axis in self ._get_axis_list ():
3202+ for axis in self ._axis_map . values ():
32063203 axis .set_zorder (zorder )
32073204 self .stale = True
32083205
@@ -3306,8 +3303,8 @@ def ticklabel_format(self, *, axis='both', style='', scilimits=None,
33063303 ) from err
33073304 STYLES = {'sci' : True , 'scientific' : True , 'plain' : False , '' : None }
33083305 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 () )}
33113308 axises = _api .check_getitem (axis_map , axis = axis )
33123309 try :
33133310 for axis in axises :
@@ -3361,7 +3358,7 @@ def locator_params(self, axis='both', tight=None, **kwargs):
33613358 _api .check_in_list ([* self ._axis_names , "both" ], axis = axis )
33623359 for name in self ._axis_names :
33633360 if axis in [name , "both" ]:
3364- loc = self ._get_axis_map () [name ].get_major_locator ()
3361+ loc = self ._axis_map [name ].get_major_locator ()
33653362 loc .set_params (** kwargs )
33663363 self ._request_autoscale_view (name , tight = tight )
33673364 self .stale = True
@@ -4412,7 +4409,7 @@ def get_children(self):
44124409 return [
44134410 * self ._children ,
44144411 * self .spines .values (),
4415- * self ._get_axis_list (),
4412+ * self ._axis_map . values (),
44164413 self .title , self ._left_title , self ._right_title ,
44174414 * self .child_axes ,
44184415 * ([self .legend_ ] if self .legend_ is not None else []),
@@ -4444,10 +4441,10 @@ def get_default_bbox_extra_artists(self):
44444441
44454442 artists = self .get_children ()
44464443
4447- for _axis in self ._get_axis_list ():
4444+ for axis in self ._axis_map . values ():
44484445 # axis tight bboxes are calculated separately inside
44494446 # Axes.get_tightbbox() using for_layout_only=True
4450- artists .remove (_axis )
4447+ artists .remove (axis )
44514448 if not (self .axison and self ._frameon ):
44524449 # don't do bbox on spines if frame not on.
44534450 for spine in self .spines .values ():
@@ -4520,7 +4517,7 @@ def get_tightbbox(self, renderer, call_axes_locator=True,
45204517 else :
45214518 self .apply_aspect ()
45224519
4523- for axis in self ._get_axis_list ():
4520+ for axis in self ._axis_map . values ():
45244521 if self .axison and axis .get_visible ():
45254522 ba = martist ._get_tightbbox_for_layout_only (axis , renderer )
45264523 if ba :
0 commit comments