Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33303ba

Browse files
authored
Merge pull request #23987 from tacaswell/fix_false_CL
FIX: do not set constrained layout on false-y values
2 parents e98d8d0 + fe1aed2 commit 33303ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2426,9 +2426,12 @@ def __init__(self,
24262426
if isinstance(tight_layout, dict):
24272427
self.get_layout_engine().set(**tight_layout)
24282428
elif constrained_layout is not None:
2429-
self.set_layout_engine(layout='constrained')
24302429
if isinstance(constrained_layout, dict):
2430+
self.set_layout_engine(layout='constrained')
24312431
self.get_layout_engine().set(**constrained_layout)
2432+
elif constrained_layout:
2433+
self.set_layout_engine(layout='constrained')
2434+
24322435
else:
24332436
# everything is None, so use default:
24342437
self.set_layout_engine(layout=layout)

lib/matplotlib/tests/test_constrainedlayout.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,14 @@ def test_compressed1():
656656
pos = axs[1, 2].get_position()
657657
np.testing.assert_allclose(pos.x1, 0.8618, atol=1e-3)
658658
np.testing.assert_allclose(pos.y0, 0.1934, atol=1e-3)
659+
660+
661+
@pytest.mark.parametrize('arg, state', [
662+
(True, True),
663+
(False, False),
664+
({}, True),
665+
({'rect': None}, True)
666+
])
667+
def test_set_constrained_layout(arg, state):
668+
fig, ax = plt.subplots(constrained_layout=arg)
669+
assert fig.get_constrained_layout() is state

0 commit comments

Comments
 (0)