diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index e47d7c083625..404179341264 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -370,7 +370,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 0dbf128fc672..007fac6ec1f9 100644 --- a/lib/matplotlib/tests/test_constrainedlayout.py +++ b/lib/matplotlib/tests/test_constrainedlayout.py @@ -537,3 +537,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.draw_no_output() + pos0 = ax.get_tightbbox(fig.canvas.get_renderer()) + fig.supxlabel('Boo') + fig.supylabel('Booy') + fig.draw_no_output() + 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.draw_no_output() + 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.draw_no_output() + pos = ax.get_tightbbox(fig.canvas.get_renderer()) + assert pos.y0 > pos0.y0 + 10.0 + assert pos.x0 > pos0.x0 + 10.0
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: