3535
3636from matplotlib .axes import Axes , SubplotBase , subplot_class_factory
3737from matplotlib .gridspec import GridSpec
38- from matplotlib .layout_engine import (ConstrainedLayoutEngine ,
39- TightLayoutEngine , LayoutEngine )
38+ from matplotlib .layout_engine import (
39+ ConstrainedLayoutEngine , TightLayoutEngine , LayoutEngine ,
40+ PlaceHolderLayoutEngine
41+ )
4042import matplotlib .legend as mlegend
4143from matplotlib .patches import Rectangle
4244from matplotlib .text import Text
@@ -2382,7 +2384,9 @@ def _check_layout_engines_compat(self, old, new):
23822384 If the figure has used the old engine and added a colorbar then the
23832385 value of colorbar_gridspec must be the same on the new engine.
23842386 """
2385- if old is None or old .colorbar_gridspec == new .colorbar_gridspec :
2387+ if old is None or new is None :
2388+ return True
2389+ if old .colorbar_gridspec == new .colorbar_gridspec :
23862390 return True
23872391 # colorbar layout different, so check if any colorbars are on the
23882392 # figure...
@@ -2398,15 +2402,29 @@ def set_layout_engine(self, layout=None, **kwargs):
23982402
23992403 Parameters
24002404 ----------
2401- layout: {'constrained', 'compressed', 'tight'} or `~.LayoutEngine`
2402- 'constrained' will use `~.ConstrainedLayoutEngine`,
2403- 'compressed' will also use ConstrainedLayoutEngine, but with a
2404- correction that attempts to make a good layout for fixed-aspect
2405- ratio Axes. 'tight' uses `~.TightLayoutEngine`. Users and
2406- libraries can define their own layout engines as well.
2405+ layout: {'constrained', 'compressed', 'tight', 'none'} or \
2406+ `LayoutEngine` or None
2407+
2408+ - 'constrained' will use `~.ConstrainedLayoutEngine`
2409+ - 'compressed' will also use `~.ConstrainedLayoutEngine`, but with
2410+ a correction that attempts to make a good layout for fixed-aspect
2411+ ratio Axes.
2412+ - 'tight' uses `~.TightLayoutEngine`
2413+ - 'none' removes layout engine.
2414+
2415+ If `None`, the behavior is controlled by :rc:`figure.autolayout`
2416+ (which if `True` behaves as if 'tight' were passed) and
2417+ :rc:`figure.constrained_layout.use` (which if true behaves as if
2418+ 'constrained' were passed). If both are true,
2419+ :rc:`figure.autolayout` takes priority.
2420+
2421+ Users and libraries can define their own layout engines and pass
2422+ the instance directly as well.
2423+
24072424 kwargs: dict
24082425 The keyword arguments are passed to the layout engine to set things
24092426 like padding and margin sizes. Only used if *layout* is a string.
2427+
24102428 """
24112429 if layout is None :
24122430 if mpl .rcParams ['figure.autolayout' ]:
@@ -2423,6 +2441,14 @@ def set_layout_engine(self, layout=None, **kwargs):
24232441 elif layout == 'compressed' :
24242442 new_layout_engine = ConstrainedLayoutEngine (compress = True ,
24252443 ** kwargs )
2444+ elif layout == 'none' :
2445+ if self ._layout_engine is not None :
2446+ new_layout_engine = PlaceHolderLayoutEngine (
2447+ self ._layout_engine .adjust_compatible ,
2448+ self ._layout_engine .colorbar_gridspec
2449+ )
2450+ else :
2451+ new_layout_engine = None
24262452 elif isinstance (layout , LayoutEngine ):
24272453 new_layout_engine = layout
24282454 else :
0 commit comments