def execute(self, fig): """ Execute tight_layout. This decides the subplot parameters given the padding that will allow the axes labels to not be covered by other labels and axes. Parameters ---------- fig : `.Figure` to perform layout on. See also: `.figure.Figure.tight_layout` and `.pyplot.tight_layout`. """ info = self._params subplotspec_list = get_subplotspec_list(fig.axes) if None in subplotspec_list: _api.warn_external("This figure includes Axes that are not " "compatible with tight_layout, so results " "might be incorrect.") renderer = _get_renderer(fig) with getattr(renderer, "_draw_disabled", nullcontext)(): kwargs = get_tight_layout_figure(fig, fig.axes, subplotspec_list, renderer, pad=info['pad'], h_pad=info['h_pad'], w_pad=info['w_pad'], rect=info['rect']) if kwargs: fig.subplots_adjust(**kwargs)
def tight_layout(self, figure, renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None): """ Adjust subplot parameters to give specified padding. Parameters ---------- pad : float Padding between the figure edge and the edges of subplots, as a fraction of the font-size. h_pad, w_pad : float, optional Padding (height/width) between edges of adjacent subplots. Defaults to *pad*. rect : tuple of 4 floats, default: (0, 0, 1, 1), i.e. the whole figure (left, bottom, right, top) rectangle in normalized figure coordinates that the whole subplots area (including labels) will fit into. """ subplotspec_list = _tight_layout.get_subplotspec_list(figure.axes, grid_spec=self) if None in subplotspec_list: _api.warn_external("This figure includes Axes that are not " "compatible with tight_layout, so results " "might be incorrect.") if renderer is None: renderer = _tight_layout.get_renderer(figure) kwargs = _tight_layout.get_tight_layout_figure(figure, figure.axes, subplotspec_list, renderer, pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect) if kwargs: self.update(**kwargs)