Do the constrained_layout. Called at draw time in ``figure.constrained_layout()`` Parameters ---------- fig: Figure is the ``figure`` instance to do the layout in. renderer: Renderer the renderer to use. h_pad, w_pad : float are in figure-norma
(fig, renderer, h_pad, w_pad,
hspace=None, wspace=None)
| 81 | |
| 82 | ###################################################### |
| 83 | def do_constrained_layout(fig, renderer, h_pad, w_pad, |
| 84 | hspace=None, wspace=None): |
| 85 | |
| 86 | """ |
| 87 | Do the constrained_layout. Called at draw time in |
| 88 | ``figure.constrained_layout()`` |
| 89 | |
| 90 | Parameters |
| 91 | ---------- |
| 92 | |
| 93 | |
| 94 | fig: Figure |
| 95 | is the ``figure`` instance to do the layout in. |
| 96 | |
| 97 | renderer: Renderer |
| 98 | the renderer to use. |
| 99 | |
| 100 | h_pad, w_pad : float |
| 101 | are in figure-normalized units, and are a padding around the axes |
| 102 | elements. |
| 103 | |
| 104 | hspace, wspace : float |
| 105 | are in fractions of the subplot sizes. |
| 106 | |
| 107 | """ |
| 108 | |
| 109 | ''' Steps: |
| 110 | |
| 111 | 1. get a list of unique gridspecs in this figure. Each gridspec will be |
| 112 | constrained separately. |
| 113 | 2. Check for gaps in the gridspecs. i.e. if not every axes slot in the |
| 114 | gridspec has been filled. If empty, add a ghost axis that is made so |
| 115 | that it cannot be seen (though visible=True). This is needed to make |
| 116 | a blank spot in the layout. |
| 117 | 3. Compare the tight_bbox of each axes to its `position`, and assume that |
| 118 | the difference is the space needed by the elements around the edge of |
| 119 | the axes (decorations) like the title, ticklabels, x-labels, etc. This |
| 120 | can include legends who overspill the axes boundaries. |
| 121 | 4. Constrain gridspec elements to line up: |
| 122 | a) if colnum0 neq colnumC, the two subplotspecs are stacked next to |
| 123 | each other, with the appropriate order. |
| 124 | b) if colnum0 == columnC line up the left or right side of the |
| 125 | _poslayoutbox (depending if it is the min or max num that is equal). |
| 126 | c) do the same for rows... |
| 127 | 5. The above doesn't constrain relative sizes of the _poslayoutboxes at |
| 128 | all, and indeed zero-size is a solution that the solver often finds more |
| 129 | convenient than expanding the sizes. Right now the solution is to compare |
| 130 | subplotspec sizes (i.e. drowsC and drows0) and constrain the larger |
| 131 | _poslayoutbox to be larger than the ratio of the sizes. i.e. if drows0 > |
| 132 | drowsC, then ax._poslayoutbox > axc._poslayoutbox * drowsC / drows0. This |
| 133 | works fine *if* the decorations are similar between the axes. If the |
| 134 | larger subplotspec has much larger axes decorations, then the constraint |
| 135 | above is incorrect. |
| 136 | |
| 137 | We need the greater than in the above, in general, rather than an equals |
| 138 | sign. Consider the case of the left column having 2 rows, and the right |
| 139 | column having 1 row. We want the top and bottom of the _poslayoutboxes to |
| 140 | line up. So that means if there are decorations on the left column axes |
no test coverage detected