@@ -718,6 +718,21 @@ def isDefault_minfmt(self):
718
718
def isDefault_minfmt (self , value ):
719
719
self .minor ._formatter_is_default = value
720
720
721
+ def _get_shared_axes (self ):
722
+ """Return Grouper of shared axes for current axis."""
723
+ return self .axes ._shared_axes [
724
+ self ._get_axis_name ()].get_siblings (self .axes )
725
+
726
+ def _get_shared_axis (self ):
727
+ """Return list of shared axis for current axis."""
728
+ name = self ._get_axis_name ()
729
+ return [ax ._axis_map [name ] for ax in self ._get_shared_axes ()]
730
+
731
+ def _get_axis_name (self ):
732
+ """Return the axis name."""
733
+ return [name for name , axis in self .axes ._axis_map .items ()
734
+ if axis is self ][0 ]
735
+
721
736
# During initialization, Axis objects often create ticks that are later
722
737
# unused; this turns out to be a very slow step. Instead, use a custom
723
738
# descriptor to make the tick lists lazy and instantiate them as needed.
@@ -801,12 +816,10 @@ def _set_axes_scale(self, value, **kwargs):
801
816
`matplotlib.scale.register_scale`. These scales can then also
802
817
be used here.
803
818
"""
804
- name , = [name for name , axis in self .axes ._axis_map .items ()
805
- if axis is self ] # The axis name.
819
+ name = self ._get_axis_name ()
806
820
old_default_lims = (self .get_major_locator ()
807
821
.nonsingular (- np .inf , np .inf ))
808
- g = self .axes ._shared_axes [name ]
809
- for ax in g .get_siblings (self .axes ):
822
+ for ax in self ._get_shared_axes ():
810
823
ax ._axis_map [name ]._set_scale (value , ** kwargs )
811
824
ax ._update_transScale ()
812
825
ax .stale = True
@@ -1172,8 +1185,7 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
1172
1185
Whether to turn on autoscaling of the x-axis. True turns on, False
1173
1186
turns off, None leaves unchanged.
1174
1187
"""
1175
- name , = [name for name , axis in self .axes ._axis_map .items ()
1176
- if axis is self ] # The axis name.
1188
+ name = self ._get_axis_name ()
1177
1189
1178
1190
self .axes ._process_unit_info ([(name , (v0 , v1 ))], convert = False )
1179
1191
v0 = self .axes ._validate_converted_limits (v0 , self .convert_units )
@@ -1211,15 +1223,15 @@ def _set_lim(self, v0, v1, *, emit=True, auto):
1211
1223
1212
1224
self .set_view_interval (v0 , v1 , ignore = True )
1213
1225
# Mark viewlims as no longer stale without triggering an autoscale.
1214
- for ax in self .axes . _shared_axes [ name ]. get_siblings ( self . axes ):
1226
+ for ax in self ._get_shared_axes ( ):
1215
1227
ax ._stale_viewlims [name ] = False
1216
1228
if auto is not None :
1217
1229
self ._set_autoscale_on (bool (auto ))
1218
1230
1219
1231
if emit :
1220
1232
self .axes .callbacks .process (f"{ name } lim_changed" , self .axes )
1221
1233
# Call all of the other axes that are shared with this one
1222
- for other in self .axes . _shared_axes [ name ]. get_siblings ( self . axes ):
1234
+ for other in self ._get_shared_axes ( ):
1223
1235
if other is not self .axes :
1224
1236
other ._axis_map [name ]._set_lim (
1225
1237
v0 , v1 , emit = False , auto = auto )
@@ -1753,16 +1765,7 @@ def set_units(self, u):
1753
1765
"""
1754
1766
if u == self .units :
1755
1767
return
1756
- for name , axis in self .axes ._axis_map .items ():
1757
- if self is axis :
1758
- shared = [
1759
- getattr (ax , f"{ name } axis" )
1760
- for ax
1761
- in self .axes ._shared_axes [name ].get_siblings (self .axes )]
1762
- break
1763
- else :
1764
- shared = [self ]
1765
- for axis in shared :
1768
+ for axis in self ._get_shared_axis ():
1766
1769
axis .units = u
1767
1770
axis ._update_axisinfo ()
1768
1771
axis .callbacks .process ('units' )
@@ -2017,17 +2020,8 @@ def _set_tick_locations(self, ticks, *, minor=False):
2017
2020
# XXX if the user changes units, the information will be lost here
2018
2021
ticks = self .convert_units (ticks )
2019
2022
locator = mticker .FixedLocator (ticks ) # validate ticks early.
2020
- for name , axis in self .axes ._axis_map .items ():
2021
- if self is axis :
2022
- shared = [
2023
- getattr (ax , f"{ name } axis" )
2024
- for ax
2025
- in self .axes ._shared_axes [name ].get_siblings (self .axes )]
2026
- break
2027
- else :
2028
- shared = [self ]
2029
2023
if len (ticks ):
2030
- for axis in shared :
2024
+ for axis in self . _get_shared_axis () :
2031
2025
# set_view_interval maintains any preexisting inversion.
2032
2026
axis .set_view_interval (min (ticks ), max (ticks ))
2033
2027
self .axes .stale = True
@@ -2088,18 +2082,15 @@ def _get_tick_boxes_siblings(self, renderer):
2088
2082
By default, it just gets bboxes for *self*.
2089
2083
"""
2090
2084
# Get the Grouper keeping track of x or y label groups for this figure.
2091
- axis_names = [
2092
- name for name , axis in self .axes ._axis_map .items ()
2093
- if name in self .figure ._align_label_groups and axis is self ]
2094
- if len (axis_names ) != 1 :
2085
+ name = self ._get_axis_name ()
2086
+ if name not in self .figure ._align_label_groups :
2095
2087
return [], []
2096
- axis_name , = axis_names
2097
- grouper = self .figure ._align_label_groups [axis_name ]
2088
+ grouper = self .figure ._align_label_groups [name ]
2098
2089
bboxes = []
2099
2090
bboxes2 = []
2100
2091
# If we want to align labels from other Axes:
2101
2092
for ax in grouper .get_siblings (self .axes ):
2102
- axis = getattr ( ax , f" { axis_name } axis" )
2093
+ axis = ax . _axis_map [ name ]
2103
2094
ticks_to_draw = axis ._update_ticks ()
2104
2095
tlb , tlb2 = axis ._get_ticklabel_bboxes (ticks_to_draw , renderer )
2105
2096
bboxes .extend (tlb )
0 commit comments