@@ -4749,13 +4749,37 @@ 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
+ if (isinstance (gs , mpl .gridspec .GridSpecFromSubplotSpec )
4763
+ and gs .nrows * gs .ncols == 6 ):
4764
+ for ax in self .figure .axes :
4765
+ if (ax is not self
4766
+ and hasattr (ax , "_colorbar_info" )
4767
+ and ax .get_subplotspec ()
4768
+ and isinstance (ax .get_subplotspec ().get_gridspec (),
4769
+ mpl .gridspec .GridSpecFromSubplotSpec )
4770
+ and (ax .get_subplotspec ().get_gridspec ()._subplot_spec
4771
+ is gs ._subplot_spec )):
4772
+ ss = gs ._subplot_spec
4773
+ break
4774
+ return ss
4775
+
4752
4776
def _label_outer_xaxis (self , * , skip_non_rectangular_axes ,
4753
4777
remove_inner_ticks = False ):
4754
4778
# see documentation in label_outer.
4755
4779
if skip_non_rectangular_axes and not isinstance (self .patch ,
4756
4780
mpl .patches .Rectangle ):
4757
4781
return
4758
- ss = self .get_subplotspec ()
4782
+ ss = self ._get_subplotspec_with_optional_colorbar ()
4759
4783
if not ss :
4760
4784
return
4761
4785
label_position = self .xaxis .get_label_position ()
@@ -4782,7 +4806,7 @@ def _label_outer_yaxis(self, *, skip_non_rectangular_axes,
4782
4806
if skip_non_rectangular_axes and not isinstance (self .patch ,
4783
4807
mpl .patches .Rectangle ):
4784
4808
return
4785
- ss = self .get_subplotspec ()
4809
+ ss = self ._get_subplotspec_with_optional_colorbar ()
4786
4810
if not ss :
4787
4811
return
4788
4812
label_position = self .yaxis .get_label_position ()
0 commit comments