Return the positions of the grid cells in figure coordinates. Parameters ---------- fig : `~matplotlib.figure.Figure` The figure the grid should be applied to. The subplot parameters (margins and spacing between subplots) are taken from *fig*
(self, fig)
| 143 | return self._row_height_ratios |
| 144 | |
| 145 | def get_grid_positions(self, fig): |
| 146 | """ |
| 147 | Return the positions of the grid cells in figure coordinates. |
| 148 | |
| 149 | Parameters |
| 150 | ---------- |
| 151 | fig : `~matplotlib.figure.Figure` |
| 152 | The figure the grid should be applied to. The subplot parameters |
| 153 | (margins and spacing between subplots) are taken from *fig*. |
| 154 | |
| 155 | Returns |
| 156 | ------- |
| 157 | bottoms, tops, lefts, rights : array |
| 158 | The bottom, top, left, right positions of the grid cells in |
| 159 | figure coordinates. |
| 160 | """ |
| 161 | nrows, ncols = self.get_geometry() |
| 162 | subplot_params = self.get_subplot_params(fig) |
| 163 | left = subplot_params.left |
| 164 | right = subplot_params.right |
| 165 | bottom = subplot_params.bottom |
| 166 | top = subplot_params.top |
| 167 | wspace = subplot_params.wspace |
| 168 | hspace = subplot_params.hspace |
| 169 | tot_width = right - left |
| 170 | tot_height = top - bottom |
| 171 | |
| 172 | # calculate accumulated heights of columns |
| 173 | cell_h = tot_height / (nrows + hspace*(nrows-1)) |
| 174 | sep_h = hspace * cell_h |
| 175 | norm = cell_h * nrows / sum(self._row_height_ratios) |
| 176 | cell_heights = [r * norm for r in self._row_height_ratios] |
| 177 | sep_heights = [0] + ([sep_h] * (nrows-1)) |
| 178 | cell_hs = np.cumsum(np.column_stack([sep_heights, cell_heights]).flat) |
| 179 | |
| 180 | # calculate accumulated widths of rows |
| 181 | cell_w = tot_width / (ncols + wspace*(ncols-1)) |
| 182 | sep_w = wspace * cell_w |
| 183 | norm = cell_w * ncols / sum(self._col_width_ratios) |
| 184 | cell_widths = [r * norm for r in self._col_width_ratios] |
| 185 | sep_widths = [0] + ([sep_w] * (ncols-1)) |
| 186 | cell_ws = np.cumsum(np.column_stack([sep_widths, cell_widths]).flat) |
| 187 | |
| 188 | fig_tops, fig_bottoms = (top - cell_hs).reshape((-1, 2)).T |
| 189 | fig_lefts, fig_rights = (left + cell_ws).reshape((-1, 2)).T |
| 190 | return fig_bottoms, fig_tops, fig_lefts, fig_rights |
| 191 | |
| 192 | @staticmethod |
| 193 | def _check_gridspec_exists(figure, nrows, ncols): |
no test coverage detected