Implements the ``tight_layout`` geometry management. See :ref:`tight_layout_guide` for details.
| 135 | |
| 136 | |
| 137 | class TightLayoutEngine(LayoutEngine): |
| 138 | """ |
| 139 | Implements the ``tight_layout`` geometry management. See |
| 140 | :ref:`tight_layout_guide` for details. |
| 141 | """ |
| 142 | _adjust_compatible = True |
| 143 | _colorbar_gridspec = True |
| 144 | |
| 145 | def __init__(self, *, pad=1.08, h_pad=None, w_pad=None, |
| 146 | rect=(0, 0, 1, 1), **kwargs): |
| 147 | """ |
| 148 | Initialize tight_layout engine. |
| 149 | |
| 150 | Parameters |
| 151 | ---------- |
| 152 | pad : float, default: 1.08 |
| 153 | Padding between the figure edge and the edges of subplots, as a |
| 154 | fraction of the font size. |
| 155 | h_pad, w_pad : float |
| 156 | Padding (height/width) between edges of adjacent subplots. |
| 157 | Defaults to *pad*. |
| 158 | rect : tuple (left, bottom, right, top), default: (0, 0, 1, 1). |
| 159 | rectangle in normalized figure coordinates that the subplots |
| 160 | (including labels) will fit into. |
| 161 | """ |
| 162 | super().__init__(**kwargs) |
| 163 | for td in ['pad', 'h_pad', 'w_pad', 'rect']: |
| 164 | # initialize these in case None is passed in above: |
| 165 | self._params[td] = None |
| 166 | self.set(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) |
| 167 | |
| 168 | def execute(self, fig): |
| 169 | """ |
| 170 | Execute tight_layout. |
| 171 | |
| 172 | This decides the subplot parameters given the padding that |
| 173 | will allow the Axes labels to not be covered by other labels |
| 174 | and Axes. |
| 175 | |
| 176 | Parameters |
| 177 | ---------- |
| 178 | fig : `.Figure` to perform layout on. |
| 179 | |
| 180 | See Also |
| 181 | -------- |
| 182 | .figure.Figure.tight_layout |
| 183 | .pyplot.tight_layout |
| 184 | """ |
| 185 | info = self._params |
| 186 | renderer = fig._get_renderer() |
| 187 | with getattr(renderer, "_draw_disabled", nullcontext)(): |
| 188 | kwargs = get_tight_layout_figure( |
| 189 | fig, fig.axes, get_subplotspec_list(fig.axes), renderer, |
| 190 | pad=info['pad'], h_pad=info['h_pad'], w_pad=info['w_pad'], |
| 191 | rect=info['rect']) |
| 192 | if kwargs: |
| 193 | fig.subplots_adjust(**kwargs) |
| 194 |
no outgoing calls
no test coverage detected
searching dependent graphs…