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
@@ -2440,7 +2442,9 @@ def _check_layout_engines_compat(self, old, new):
24402442 If the figure has used the old engine and added a colorbar then the
24412443 value of colorbar_gridspec must be the same on the new engine.
24422444 """
2443- if old is None or old .colorbar_gridspec == new .colorbar_gridspec :
2445+ if old is None or new is None :
2446+ return True
2447+ if old .colorbar_gridspec == new .colorbar_gridspec :
24442448 return True
24452449 # colorbar layout different, so check if any colorbars are on the
24462450 # figure...
@@ -2456,15 +2460,29 @@ def set_layout_engine(self, layout=None, **kwargs):
24562460
24572461 Parameters
24582462 ----------
2459- layout: {'constrained', 'compressed', 'tight'} or `~.LayoutEngine`
2460- 'constrained' will use `~.ConstrainedLayoutEngine`,
2461- 'compressed' will also use ConstrainedLayoutEngine, but with a
2462- correction that attempts to make a good layout for fixed-aspect
2463- ratio Axes. 'tight' uses `~.TightLayoutEngine`. Users and
2464- libraries can define their own layout engines as well.
2463+ layout: {'constrained', 'compressed', 'tight', 'none'} or \
2464+ `LayoutEngine` or None
2465+
2466+ - 'constrained' will use `~.ConstrainedLayoutEngine`
2467+ - 'compressed' will also use `~.ConstrainedLayoutEngine`, but with
2468+ a correction that attempts to make a good layout for fixed-aspect
2469+ ratio Axes.
2470+ - 'tight' uses `~.TightLayoutEngine`
2471+ - 'none' removes layout engine.
2472+
2473+ If `None`, the behavior is controlled by :rc:`figure.autolayout`
2474+ (which if `True` behaves as if 'tight' were passed) and
2475+ :rc:`figure.constrained_layout.use` (which if `True` behaves as if
2476+ 'constrained' were passed). If both are `True`,
2477+ :rc:`figure.autolayout` takes priority.
2478+
2479+ Users and libraries can define their own layout engines and pass
2480+ the instance directly as well.
2481+
24652482 kwargs: dict
24662483 The keyword arguments are passed to the layout engine to set things
24672484 like padding and margin sizes. Only used if *layout* is a string.
2485+
24682486 """
24692487 if layout is None :
24702488 if mpl .rcParams ['figure.autolayout' ]:
@@ -2481,6 +2499,14 @@ def set_layout_engine(self, layout=None, **kwargs):
24812499 elif layout == 'compressed' :
24822500 new_layout_engine = ConstrainedLayoutEngine (compress = True ,
24832501 ** kwargs )
2502+ elif layout == 'none' :
2503+ if self ._layout_engine is not None :
2504+ new_layout_engine = PlaceHolderLayoutEngine (
2505+ self ._layout_engine .adjust_compatible ,
2506+ self ._layout_engine .colorbar_gridspec
2507+ )
2508+ else :
2509+ new_layout_engine = None
24842510 elif isinstance (layout , LayoutEngine ):
24852511 new_layout_engine = layout
24862512 else :
0 commit comments