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

Skip to content

Commit cb0410a

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 cb0410a

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 8 additions & 2 deletions
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...
@@ -2329,10 +2331,12 @@ def set_layout_engine(self, layout=None, **kwargs):
23292331
23302332
Parameters
23312333
----------
2332-
layout: {'constrained', 'tight'} or `~.LayoutEngine`
2334+
layout: {'constrained', 'tight', 'none'} or `~.LayoutEngine`
23332335
'constrained' will use `~.ConstrainedLayoutEngine`, 'tight' will
23342336
use `~.TightLayoutEngine`. Users and libraries can define their
23352337
own layout engines as well.
2338+
2339+
The string 'none' removes layout engine.
23362340
kwargs: dict
23372341
The keyword arguments are passed to the layout engine to set things
23382342
like padding and margin sizes. Only used if *layout* is a string.
@@ -2349,6 +2353,8 @@ def set_layout_engine(self, layout=None, **kwargs):
23492353
new_layout_engine = TightLayoutEngine(**kwargs)
23502354
elif layout == 'constrained':
23512355
new_layout_engine = ConstrainedLayoutEngine(**kwargs)
2356+
elif layout == 'none':
2357+
new_layout_engine = None
23522358
elif isinstance(layout, LayoutEngine):
23532359
new_layout_engine = layout
23542360
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)