diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 2e5830ec2463..93e11da52e9e 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -2533,6 +2533,8 @@ def set_tight_layout(self, tight): _tight_parameters = tight if isinstance(tight, dict) else {} if bool(tight): self.set_layout_engine(TightLayoutEngine(**_tight_parameters)) + else: + self.set_layout_engine(None) self.stale = True def get_constrained_layout(self): @@ -2569,6 +2571,8 @@ def set_constrained_layout(self, constrained): _parameters = constrained if isinstance(constrained, dict) else {} if _constrained: self.set_layout_engine(ConstrainedLayoutEngine(**_parameters)) + else: + self.set_layout_engine(None) self.stale = True @_api.deprecated( diff --git a/lib/matplotlib/tests/test_constrainedlayout.py b/lib/matplotlib/tests/test_constrainedlayout.py index b3aea15adad3..27c60892f4f2 100644 --- a/lib/matplotlib/tests/test_constrainedlayout.py +++ b/lib/matplotlib/tests/test_constrainedlayout.py @@ -608,3 +608,12 @@ def test_discouraged_api(): def test_kwargs(): fig, ax = plt.subplots(constrained_layout={'h_pad': 0.02}) fig.draw_without_rendering() + + +def test_constrained_toggle(): + fig, ax = plt.subplots() + with pytest.warns(PendingDeprecationWarning): + fig.set_constrained_layout(True) + assert fig.get_constrained_layout() + fig.set_constrained_layout(False) + assert not fig.get_constrained_layout() diff --git a/lib/matplotlib/tests/test_tightlayout.py b/lib/matplotlib/tests/test_tightlayout.py index 1eb7b4b4534f..2b24e77d0740 100644 --- a/lib/matplotlib/tests/test_tightlayout.py +++ b/lib/matplotlib/tests/test_tightlayout.py @@ -380,3 +380,12 @@ def test_tight_pads(): def test_tight_kwargs(): fig, ax = plt.subplots(tight_layout={'pad': 0.15}) fig.draw_without_rendering() + + +def test_tight_toggle(): + fig, ax = plt.subplots() + with pytest.warns(PendingDeprecationWarning): + fig.set_tight_layout(True) + assert fig.get_tight_layout() + fig.set_tight_layout(False) + assert not fig.get_tight_layout()