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)
| 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}") |