@@ -262,6 +262,28 @@ def _alty_overrides(self):
262262 self .xaxis .set_visible (False )
263263 self .patch .set_visible (False )
264264
265+ def _apply_axis_sharing (self ):
266+ """
267+ Enforce the "shared" axis labels and axis tick labels. If this is
268+ not called at drawtime, "shared" labels can be inadvertantly turned
269+ off e.g. when the axis scale is changed.
270+ """
271+ for x in 'xy' :
272+ # "Shared" axis and tick labels
273+ axis = getattr (self , x + 'axis' )
274+ share = getattr (self , '_share' + x )
275+ if share is not None :
276+ level = (
277+ 3 if getattr (self , '_share' + x + '_override' )
278+ else getattr (self .figure , '_share' + x )
279+ )
280+ if level > 0 :
281+ axis .label .set_visible (False )
282+ if level > 2 :
283+ axis .set_major_formatter (mticker .NullFormatter ())
284+ # Enforce no minor ticks labels. TODO: Document?
285+ axis .set_minor_formatter (mticker .NullFormatter ())
286+
265287 def _datex_rotate (self ):
266288 """
267289 Apply default rotation to datetime axis coordinates.
@@ -335,28 +357,6 @@ def _dualy_overrides(self):
335357 child .set_ylim (nlim , emit = False )
336358 self ._dualy_cache = (scale , * olim )
337359
338- def _hide_labels (self ):
339- """
340- Enforce the "shared" axis labels and axis tick labels. If this is
341- not called at drawtime, "shared" labels can be inadvertantly turned
342- off e.g. when the axis scale is changed.
343- """
344- for x in 'xy' :
345- # "Shared" axis and tick labels
346- axis = getattr (self , x + 'axis' )
347- share = getattr (self , '_share' + x )
348- if share is not None :
349- level = (
350- 3 if getattr (self , '_share' + x + '_override' )
351- else getattr (self .figure , '_share' + x )
352- )
353- if level > 0 :
354- axis .label .set_visible (False )
355- if level > 2 :
356- axis .set_major_formatter (mticker .NullFormatter ())
357- # Enforce no minor ticks labels. TODO: Document?
358- axis .set_minor_formatter (mticker .NullFormatter ())
359-
360360 def _make_twin_axes (self , * args , ** kwargs ):
361361 """
362362 Return a twin of this axes. This is used for twinx and twiny and was
@@ -1185,7 +1185,7 @@ def draw(self, renderer=None, *args, **kwargs):
11851185 # Perform extra post-processing steps
11861186 # NOTE: This mimics matplotlib API, which calls identical
11871187 # post-processing steps in both draw() and get_tightbbox()
1188- self ._hide_labels ()
1188+ self ._apply_axis_sharing ()
11891189 self ._altx_overrides ()
11901190 self ._alty_overrides ()
11911191 self ._dualx_overrides ()
@@ -1197,7 +1197,7 @@ def draw(self, renderer=None, *args, **kwargs):
11971197
11981198 def get_tightbbox (self , renderer , * args , ** kwargs ):
11991199 # Perform extra post-processing steps
1200- self ._hide_labels ()
1200+ self ._apply_axis_sharing ()
12011201 self ._altx_overrides ()
12021202 self ._alty_overrides ()
12031203 self ._dualx_overrides ()
0 commit comments