diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index ba670f55c63c..a60658c7addf 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -373,7 +373,10 @@ def _suplabels(self, t, info, **kwargs): x = kwargs.pop('x', None) y = kwargs.pop('y', None) - autopos = x is None and y is None + if info['name'] in ['_supxlabel', '_suptitle']: + autopos = y is None + elif info['name'] == '_supylabel': + autopos = x is None if x is None: x = info['x0'] if y is None: diff --git a/lib/matplotlib/tests/test_constrainedlayout.py b/lib/matplotlib/tests/test_constrainedlayout.py index 67474628e7bf..117b221cc21a 100644 --- a/lib/matplotlib/tests/test_constrainedlayout.py +++ b/lib/matplotlib/tests/test_constrainedlayout.py @@ -555,3 +555,26 @@ def test_align_labels(): after_align[1].x0, rtol=0, atol=1e-05) # ensure labels do not go off the edge assert after_align[0].x0 >= 1 + + +def test_suplabels(): + fig, ax = plt.subplots(constrained_layout=True) + fig.canvas.draw() + pos0 = ax.get_tightbbox(fig.canvas.get_renderer()) + fig.supxlabel('Boo') + fig.supylabel('Booy') + fig.canvas.draw() + pos = ax.get_tightbbox(fig.canvas.get_renderer()) + assert pos.y0 > pos0.y0 + 10.0 + assert pos.x0 > pos0.x0 + 10.0 + + fig, ax = plt.subplots(constrained_layout=True) + fig.canvas.draw() + pos0 = ax.get_tightbbox(fig.canvas.get_renderer()) + # check that specifying x (y) doesn't ruin the layout + fig.supxlabel('Boo', x=0.5) + fig.supylabel('Boo', y=0.5) + fig.canvas.draw() + pos = ax.get_tightbbox(fig.canvas.get_renderer()) + assert pos.y0 > pos0.y0 + 10.0 + assert pos.x0 > pos0.x0 + 10.0