@@ -4749,14 +4749,25 @@ def label_outer(self, remove_inner_ticks=False):
47494749 self ._label_outer_yaxis (skip_non_rectangular_axes = False ,
47504750 remove_inner_ticks = remove_inner_ticks )
47514751
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 any (cax .get_subplotspec () for cax in self ._colorbars ):
4760+ ss = ss .get_gridspec ()._subplot_spec
4761+ return ss
4762+
47524763 def _label_outer_xaxis (self , * , skip_non_rectangular_axes ,
47534764 remove_inner_ticks = False ):
47544765 # see documentation in label_outer.
47554766 if skip_non_rectangular_axes and not isinstance (self .patch ,
47564767 mpl .patches .Rectangle ):
47574768 return
4758- ss = self .get_subplotspec ()
4759- if not ss :
4769+ ss = self ._get_subplotspec_with_optional_colorbar ()
4770+ if ss is None :
47604771 return
47614772 label_position = self .xaxis .get_label_position ()
47624773 if not ss .is_first_row (): # Remove top label/ticklabels/offsettext.
@@ -4782,8 +4793,8 @@ def _label_outer_yaxis(self, *, skip_non_rectangular_axes,
47824793 if skip_non_rectangular_axes and not isinstance (self .patch ,
47834794 mpl .patches .Rectangle ):
47844795 return
4785- ss = self .get_subplotspec ()
4786- if not ss :
4796+ ss = self ._get_subplotspec_with_optional_colorbar ()
4797+ if ss is None :
47874798 return
47884799 label_position = self .yaxis .get_label_position ()
47894800 if not ss .is_first_col (): # Remove left label/ticklabels/offsettext.
0 commit comments