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
@@ -2440,7 +2442,9 @@ def _check_layout_engines_compat(self, old, new):
2440
2442
If the figure has used the old engine and added a colorbar then the
2441
2443
value of colorbar_gridspec must be the same on the new engine.
2442
2444
"""
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 :
2444
2448
return True
2445
2449
# colorbar layout different, so check if any colorbars are on the
2446
2450
# figure...
@@ -2456,15 +2460,29 @@ def set_layout_engine(self, layout=None, **kwargs):
2456
2460
2457
2461
Parameters
2458
2462
----------
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
+
2465
2482
kwargs: dict
2466
2483
The keyword arguments are passed to the layout engine to set things
2467
2484
like padding and margin sizes. Only used if *layout* is a string.
2485
+
2468
2486
"""
2469
2487
if layout is None :
2470
2488
if mpl .rcParams ['figure.autolayout' ]:
@@ -2481,6 +2499,14 @@ def set_layout_engine(self, layout=None, **kwargs):
2481
2499
elif layout == 'compressed' :
2482
2500
new_layout_engine = ConstrainedLayoutEngine (compress = True ,
2483
2501
** 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
2484
2510
elif isinstance (layout , LayoutEngine ):
2485
2511
new_layout_engine = layout
2486
2512
else :
0 commit comments