@@ -4749,14 +4749,39 @@ def label_outer(self, remove_inner_ticks=False):
4749
4749
self ._label_outer_yaxis (skip_non_rectangular_axes = False ,
4750
4750
remove_inner_ticks = remove_inner_ticks )
4751
4751
4752
+ def _get_subplotspec_with_optional_colorbar (self ):
4753
+ """
4754
+ Return the subplotspec for this Axes, except that if this Axes has been
4755
+ moved to a subgridspec to make room for a colorbar, then return the
4756
+ subplotspec that encloses both this Axes and the colorbar Axes.
4757
+ """
4758
+ ss = self .get_subplotspec ()
4759
+ if not ss :
4760
+ return
4761
+ gs = ss .get_gridspec ()
4762
+ # Match against subgridspec hierarchy set up by colorbar.make_axes_gridspec.
4763
+ if (isinstance (gs ,mpl .gridspec .GridSpecFromSubplotSpec )
4764
+ and gs .nrows * gs .ncols == 6 ):
4765
+ for ax in self .figure .axes :
4766
+ if (ax is not self
4767
+ and hasattr (ax ,"_colorbar_info" )
4768
+ and ax .get_subplotspec ()
4769
+ and isinstance (ax .get_subplotspec ().get_gridspec (),
4770
+ mpl .gridspec .GridSpecFromSubplotSpec )
4771
+ and (ax .get_subplotspec ().get_gridspec ()._subplot_spec
4772
+ is gs ._subplot_spec )):
4773
+ ss = gs ._subplot_spec
4774
+ break
4775
+ return ss
4776
+
4752
4777
def _label_outer_xaxis (self ,* ,skip_non_rectangular_axes ,
4753
4778
remove_inner_ticks = False ):
4754
4779
# see documentation in label_outer.
4755
4780
if skip_non_rectangular_axes and not isinstance (self .patch ,
4756
4781
mpl .patches .Rectangle ):
4757
4782
return
4758
- ss = self .get_subplotspec ()
4759
- if not ss :
4783
+ ss = self ._get_subplotspec_with_optional_colorbar ()
4784
+ if ss is None :
4760
4785
return
4761
4786
label_position = self .xaxis .get_label_position ()
4762
4787
if not ss .is_first_row ():# Remove top label/ticklabels/offsettext.
@@ -4782,8 +4807,8 @@ def _label_outer_yaxis(self, *, skip_non_rectangular_axes,
4782
4807
if skip_non_rectangular_axes and not isinstance (self .patch ,
4783
4808
mpl .patches .Rectangle ):
4784
4809
return
4785
- ss = self .get_subplotspec ()
4786
- if not ss :
4810
+ ss = self ._get_subplotspec_with_optional_colorbar ()
4811
+ if ss is None :
4787
4812
return
4788
4813
label_position = self .yaxis .get_label_position ()
4789
4814
if not ss .is_first_col ():# Remove left label/ticklabels/offsettext.