Skip to content

Commit b0c1c49

Browse files
committed
ENH: add ability to remove layout engine
This may be too simplistic as it just sets it to None which gives you ability to "go through zero" and change to an incompatible layout engine.
1 parent bba8e9e commit b0c1c49

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/matplotlib/figure.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2313,7 +2313,9 @@ def _check_layout_engines_compat(self, old, new):
23132313
If the figure has used the old engine and added a colorbar then the
23142314
value of colorbar_gridspec must be the same on the new engine.
23152315
"""
2316-
if old is None or old.colorbar_gridspec == new.colorbar_gridspec:
2316+
if old is None or new is None:
2317+
return True
2318+
if old.colorbar_gridspec == new.colorbar_gridspec:
23172319
return True
23182320
# colorbar layout different, so check if any colorbars are on the
23192321
# figure...
@@ -2349,6 +2351,8 @@ def set_layout_engine(self, layout=None, **kwargs):
23492351
new_layout_engine = TightLayoutEngine(**kwargs)
23502352
elif layout == 'constrained':
23512353
new_layout_engine = ConstrainedLayoutEngine(**kwargs)
2354+
elif layout == 'none':
2355+
new_layout_engine = None
23522356
elif isinstance(layout, LayoutEngine):
23532357
new_layout_engine = layout
23542358
else:

lib/matplotlib/tests/test_figure.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ def test_invalid_layouts():
620620
with pytest.raises(RuntimeError, match='Colorbar layout of new layout'):
621621
fig.set_layout_engine("constrained")
622622

623+
fig.set_layout_engine("none")
624+
assert fig.get_layout_engine() is None
625+
623626

624627
@check_figures_equal(extensions=["png", "pdf"])
625628
def test_add_artist(fig_test, fig_ref):

0 commit comments

Comments
 (0)