Return subplot parameters for tight-layouted-figure with specified padding. Parameters ---------- fig : Figure axes_list : list of Axes subplotspec_list : list of `.SubplotSpec` The subplotspecs of each Axes. renderer : renderer pad : float Padding b
(fig, axes_list, subplotspec_list, renderer,
pad=1.08, h_pad=None, w_pad=None, rect=None)
| 192 | |
| 193 | |
| 194 | def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer, |
| 195 | pad=1.08, h_pad=None, w_pad=None, rect=None): |
| 196 | """ |
| 197 | Return subplot parameters for tight-layouted-figure with specified padding. |
| 198 | |
| 199 | Parameters |
| 200 | ---------- |
| 201 | fig : Figure |
| 202 | axes_list : list of Axes |
| 203 | subplotspec_list : list of `.SubplotSpec` |
| 204 | The subplotspecs of each Axes. |
| 205 | renderer : renderer |
| 206 | pad : float |
| 207 | Padding between the figure edge and the edges of subplots, as a |
| 208 | fraction of the font size. |
| 209 | h_pad, w_pad : float |
| 210 | Padding (height/width) between edges of adjacent subplots. Defaults to |
| 211 | *pad*. |
| 212 | rect : tuple (left, bottom, right, top), default: None. |
| 213 | rectangle in normalized figure coordinates |
| 214 | that the whole subplots area (including labels) will fit into. |
| 215 | Defaults to using the entire figure. |
| 216 | |
| 217 | Returns |
| 218 | ------- |
| 219 | subplotspec or None |
| 220 | subplotspec kwargs to be passed to `.Figure.subplots_adjust` or |
| 221 | None if tight_layout could not be accomplished. |
| 222 | """ |
| 223 | |
| 224 | # Multiple Axes can share same subplotspec (e.g., if using axes_grid1); |
| 225 | # we need to group them together. |
| 226 | ss_to_subplots = {ss: [] for ss in subplotspec_list} |
| 227 | for ax, ss in zip(axes_list, subplotspec_list): |
| 228 | ss_to_subplots[ss].append(ax) |
| 229 | if ss_to_subplots.pop(None, None): |
| 230 | _api.warn_external( |
| 231 | "This figure includes Axes that are not compatible with " |
| 232 | "tight_layout, so results might be incorrect.") |
| 233 | if not ss_to_subplots: |
| 234 | return {} |
| 235 | subplot_list = list(ss_to_subplots.values()) |
| 236 | ax_bbox_list = [ss.get_position(fig) for ss in ss_to_subplots] |
| 237 | |
| 238 | max_nrows = max(ss.get_gridspec().nrows for ss in ss_to_subplots) |
| 239 | max_ncols = max(ss.get_gridspec().ncols for ss in ss_to_subplots) |
| 240 | |
| 241 | span_pairs = [] |
| 242 | for ss in ss_to_subplots: |
| 243 | # The intent here is to support Axes from different gridspecs where |
| 244 | # one's nrows (or ncols) is a multiple of the other (e.g. 2 and 4), |
| 245 | # but this doesn't actually work because the computed wspace, in |
| 246 | # relative-axes-height, corresponds to different physical spacings for |
| 247 | # the 2-row grid and the 4-row grid. Still, this code is left, mostly |
| 248 | # for backcompat. |
| 249 | rows, cols = ss.get_gridspec().get_geometry() |
| 250 | div_row, mod_row = divmod(max_nrows, rows) |
| 251 | div_col, mod_col = divmod(max_ncols, cols) |
no test coverage detected
searching dependent graphs…