Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2426,9 +2426,12 @@ def __init__(self,
if isinstance(tight_layout, dict):
self.get_layout_engine().set(**tight_layout)
elif constrained_layout is not None:
self.set_layout_engine(layout='constrained')
if isinstance(constrained_layout, dict):
self.set_layout_engine(layout='constrained')
self.get_layout_engine().set(**constrained_layout)
elif constrained_layout:
self.set_layout_engine(layout='constrained')

else:
# everything is None, so use default:
self.set_layout_engine(layout=layout)
Expand Down
11 changes: 11 additions & 0 deletions lib/matplotlib/tests/test_constrainedlayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,3 +656,14 @@ def test_compressed1():
pos = axs[1, 2].get_position()
np.testing.assert_allclose(pos.x1, 0.8618, atol=1e-3)
np.testing.assert_allclose(pos.y0, 0.1934, atol=1e-3)


@pytest.mark.parametrize('arg, state', [
(True, True),
(False, False),
({}, True),
({'rect': None}, True)
])
def test_set_constrained_lyout(arg, state):
Comment thread
tacaswell marked this conversation as resolved.
Outdated
fig, ax = plt.subplots(constrained_layout=arg)
assert fig.get_constrained_layout() is state