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

Skip to content

Commit bf8a992

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 80c2fdc commit bf8a992

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/matplotlib/figure.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,9 @@ def _check_layout_engines_compat(self, old, new):
23142314
If the figure has used the old engine and added a colorbar then the
23152315
value of colorbar_gridspec must be the same on the new engine.
23162316
"""
2317-
if old is None or old.colorbar_gridspec == new.colorbar_gridspec:
2317+
if old is None or new is None:
2318+
return True
2319+
if old.colorbar_gridspec == new.colorbar_gridspec:
23182320
return True
23192321
# colorbar layout different, so check if any colorbars are on the
23202322
# figure...
@@ -2330,10 +2332,13 @@ def set_layout_engine(self, layout=None, **kwargs):
23302332
23312333
Parameters
23322334
----------
2333-
layout : {'constrained', 'tight'} or `~.LayoutEngine`
2335+
layout : {'constrained', 'tight', 'none'} or `~.LayoutEngine`
23342336
'constrained' will use `~.ConstrainedLayoutEngine`, 'tight' will
23352337
use `~.TightLayoutEngine`. Users and libraries can define their
23362338
own layout engines as well.
2339+
2340+
The string 'none' removes layout engine.
2341+
23372342
kwargs : dict
23382343
The keyword arguments are passed to the layout engine to set things
23392344
like padding and margin sizes. Only used if *layout* is a string.
@@ -2350,6 +2355,8 @@ def set_layout_engine(self, layout=None, **kwargs):
23502355
new_layout_engine = TightLayoutEngine(**kwargs)
23512356
elif layout == 'constrained':
23522357
new_layout_engine = ConstrainedLayoutEngine(**kwargs)
2358+
elif layout == 'none':
2359+
new_layout_engine = None
23532360
elif isinstance(layout, LayoutEngine):
23542361
new_layout_engine = layout
23552362
else:

lib/matplotlib/tests/test_figure.py

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

622+
fig.set_layout_engine("none")
623+
assert fig.get_layout_engine() is None
624+
622625

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

0 commit comments

Comments
 (0)