diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 926944e5a577..32c5388592d0 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -3515,7 +3515,7 @@ def tight_layout(self, *, pad=1.08, h_pad=None, w_pad=None, rect=None): and previous_engine is not None: _api.warn_external('The figure layout has changed to tight') finally: - self.set_layout_engine(None) + self.set_layout_engine('none') def figaspect(arg): diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index d8b06003cd00..4188ca878fed 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -659,6 +659,15 @@ def test_invalid_layouts(): fig.set_layout_engine("constrained") +@check_figures_equal(extensions=["png"]) +def test_tightlayout_autolayout_deconflict(fig_test, fig_ref): + for fig, autolayout in zip([fig_ref, fig_test], [False, True]): + with mpl.rc_context({'figure.autolayout': autolayout}): + axes = fig.subplots(ncols=2) + fig.tight_layout(w_pad=10) + assert isinstance(fig.get_layout_engine(), PlaceHolderLayoutEngine) + + @pytest.mark.parametrize('layout', ['constrained', 'compressed']) def test_layout_change_warning(layout): """