Do the constrained_layout. Called at draw time in ``figure.constrained_layout()`` Parameters ---------- fig : `~matplotlib.figure.Figure` `.Figure` instance to do the layout in. h_pad, w_pad : float Padding around the Axes elements in figure-normalized unit
(fig, h_pad, w_pad,
hspace=None, wspace=None, rect=(0, 0, 1, 1),
compress=False)
| 61 | |
| 62 | ###################################################### |
| 63 | def do_constrained_layout(fig, h_pad, w_pad, |
| 64 | hspace=None, wspace=None, rect=(0, 0, 1, 1), |
| 65 | compress=False): |
| 66 | """ |
| 67 | Do the constrained_layout. Called at draw time in |
| 68 | ``figure.constrained_layout()`` |
| 69 | |
| 70 | Parameters |
| 71 | ---------- |
| 72 | fig : `~matplotlib.figure.Figure` |
| 73 | `.Figure` instance to do the layout in. |
| 74 | |
| 75 | h_pad, w_pad : float |
| 76 | Padding around the Axes elements in figure-normalized units. |
| 77 | |
| 78 | hspace, wspace : float |
| 79 | Fraction of the figure to dedicate to space between the |
| 80 | Axes. These are evenly spread between the gaps between the Axes. |
| 81 | A value of 0.2 for a three-column layout would have a space |
| 82 | of 0.1 of the figure width between each column. |
| 83 | If h/wspace < h/w_pad, then the pads are used instead. |
| 84 | |
| 85 | rect : tuple of 4 floats |
| 86 | Rectangle in figure coordinates to perform constrained layout in |
| 87 | [left, bottom, width, height], each from 0-1. |
| 88 | |
| 89 | compress : bool |
| 90 | Whether to shift Axes so that white space in between them is |
| 91 | removed. This is useful for simple grids of fixed-aspect Axes (e.g. |
| 92 | a grid of images). |
| 93 | |
| 94 | Returns |
| 95 | ------- |
| 96 | layoutgrid : private debugging structure |
| 97 | """ |
| 98 | |
| 99 | renderer = fig._get_renderer() |
| 100 | # make layoutgrid tree... |
| 101 | layoutgrids = make_layoutgrids(fig, None, rect=rect) |
| 102 | if not layoutgrids['hasgrids']: |
| 103 | _api.warn_external('There are no gridspecs with layoutgrids. ' |
| 104 | 'Possibly did not call parent GridSpec with the' |
| 105 | ' "figure" keyword') |
| 106 | return |
| 107 | |
| 108 | for _ in range(2): |
| 109 | # do the algorithm twice. This has to be done because decorations |
| 110 | # change size after the first re-position (i.e. x/yticklabels get |
| 111 | # larger/smaller). This second reposition tends to be much milder, |
| 112 | # so doing twice makes things work OK. |
| 113 | |
| 114 | # make margins for all the Axes and subfigures in the |
| 115 | # figure. Add margins for colorbars... |
| 116 | make_layout_margins(layoutgrids, fig, renderer, h_pad=h_pad, |
| 117 | w_pad=w_pad, hspace=hspace, wspace=wspace) |
| 118 | make_margin_suptitles(layoutgrids, fig, renderer, h_pad=h_pad, |
| 119 | w_pad=w_pad) |
| 120 |
no test coverage detected
searching dependent graphs…