35
35
36
36
from matplotlib .axes import Axes , SubplotBase , subplot_class_factory
37
37
from 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
+ )
40
42
import matplotlib .legend as mlegend
41
43
from matplotlib .patches import Rectangle
42
44
from matplotlib .text import Text
@@ -2382,7 +2384,9 @@ def _check_layout_engines_compat(self, old, new):
2382
2384
If the figure has used the old engine and added a colorbar then the
2383
2385
value of colorbar_gridspec must be the same on the new engine.
2384
2386
"""
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 :
2386
2390
return True
2387
2391
# colorbar layout different, so check if any colorbars are on the
2388
2392
# figure...
@@ -2398,15 +2402,29 @@ def set_layout_engine(self, layout=None, **kwargs):
2398
2402
2399
2403
Parameters
2400
2404
----------
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
+
2407
2424
kwargs: dict
2408
2425
The keyword arguments are passed to the layout engine to set things
2409
2426
like padding and margin sizes. Only used if *layout* is a string.
2427
+
2410
2428
"""
2411
2429
if layout is None :
2412
2430
if mpl .rcParams ['figure.autolayout' ]:
@@ -2423,6 +2441,14 @@ def set_layout_engine(self, layout=None, **kwargs):
2423
2441
elif layout == 'compressed' :
2424
2442
new_layout_engine = ConstrainedLayoutEngine (compress = True ,
2425
2443
** 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
2426
2452
elif isinstance (layout , LayoutEngine ):
2427
2453
new_layout_engine = layout
2428
2454
else :
0 commit comments