Skip to content

fix and test deprecated layout method toggling #22849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_constrainedlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_tightlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()