MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / set_layout_engine

Method set_layout_engine

lib/matplotlib/figure.py:2688–2753  ·  view source on GitHub ↗

Set the layout engine for this figure. Parameters ---------- layout : {'constrained', 'compressed', 'tight', 'none', `.LayoutEngine`, None} - 'constrained' will use `~.ConstrainedLayoutEngine` - 'compressed' will also use `~.ConstrainedLayou

(self, layout=None, **kwargs)

Source from the content-addressed store, hash-verified

2686 return True
2687
2688 def set_layout_engine(self, layout=None, **kwargs):
2689 """
2690 Set the layout engine for this figure.
2691
2692 Parameters
2693 ----------
2694 layout : {'constrained', 'compressed', 'tight', 'none', `.LayoutEngine`, None}
2695
2696 - 'constrained' will use `~.ConstrainedLayoutEngine`
2697 - 'compressed' will also use `~.ConstrainedLayoutEngine`, but with
2698 a correction that attempts to make a good layout for fixed-aspect
2699 ratio Axes.
2700 - 'tight' uses `~.TightLayoutEngine`
2701 - 'none' removes layout engine.
2702
2703 If a `.LayoutEngine` instance, that instance will be used.
2704
2705 If `None`, the behavior is controlled by :rc:`figure.autolayout`
2706 (which if `True` behaves as if 'tight' was passed) and
2707 :rc:`figure.constrained_layout.use` (which if `True` behaves as if
2708 'constrained' was passed). If both are `True`,
2709 :rc:`figure.autolayout` takes priority.
2710
2711 Users and libraries can define their own layout engines and pass
2712 the instance directly as well.
2713
2714 **kwargs
2715 The keyword arguments are passed to the layout engine to set things
2716 like padding and margin sizes. Only used if *layout* is a string.
2717
2718 """
2719 if layout is None:
2720 if mpl.rcParams['figure.autolayout']:
2721 layout = 'tight'
2722 elif mpl.rcParams['figure.constrained_layout.use']:
2723 layout = 'constrained'
2724 else:
2725 self._layout_engine = None
2726 return
2727 if layout == 'tight':
2728 new_layout_engine = TightLayoutEngine(**kwargs)
2729 elif layout == 'constrained':
2730 new_layout_engine = ConstrainedLayoutEngine(**kwargs)
2731 elif layout == 'compressed':
2732 new_layout_engine = ConstrainedLayoutEngine(compress=True,
2733 **kwargs)
2734 elif layout == 'none':
2735 if self._layout_engine is not None:
2736 new_layout_engine = PlaceHolderLayoutEngine(
2737 self._layout_engine.adjust_compatible,
2738 self._layout_engine.colorbar_gridspec
2739 )
2740 else:
2741 new_layout_engine = None
2742 elif isinstance(layout, LayoutEngine):
2743 new_layout_engine = layout
2744 else:
2745 raise ValueError(f"Invalid value for 'layout': {layout!r}")

Callers 10

__init__Method · 0.95
set_tight_layoutMethod · 0.95
tight_layoutMethod · 0.95
test_invalid_layoutsFunction · 0.95
test_tick_not_in_layoutFunction · 0.80
test_all_nestedMethod · 0.80
test_nestedMethod · 0.80
test_tight_layout8Function · 0.80

Tested by 5

test_invalid_layoutsFunction · 0.76
test_tick_not_in_layoutFunction · 0.64
test_all_nestedMethod · 0.64
test_nestedMethod · 0.64
test_tight_layout8Function · 0.64