diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 385395c0d448..6fdf1265ff3b 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2092,6 +2092,12 @@ def subplots_adjust(self, left=None, bottom=None, right=None, top=None, *None*) and update the subplot locations. """ + if self.get_constrained_layout(): + self.set_constrained_layout(False) + warnings.warn("This figure was using constrained_layout==True, " + "but that is incompatible with subplots_adjust and " + "or tight_layout: setting " + "constrained_layout==False. ") self.subplotpars.update(left, bottom, right, top, wspace, hspace) for ax in self.axes: if not isinstance(ax, SubplotBase): diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index d0079012a5e6..de5a6c8aa0dd 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -373,6 +373,14 @@ def test_figure_repr(): assert repr(fig) == "
" +def test_warn_cl_plus_tl(): + fig, ax = plt.subplots(constrained_layout=True) + with pytest.warns(UserWarning): + # this should warn, + fig.subplots_adjust(top=0.8) + assert not(fig.get_constrained_layout()) + + @pytest.mark.skipif(sys.version_info < (3, 6), reason="requires Python 3.6+") @pytest.mark.parametrize("fmt", ["png", "pdf", "ps", "eps", "svg"]) def test_fspath(fmt, tmpdir):