Check if the figure already has a gridspec with these dimensions, or create a new one
(figure, nrows, ncols)
| 191 | |
| 192 | @staticmethod |
| 193 | def _check_gridspec_exists(figure, nrows, ncols): |
| 194 | """ |
| 195 | Check if the figure already has a gridspec with these dimensions, |
| 196 | or create a new one |
| 197 | """ |
| 198 | for ax in figure.get_axes(): |
| 199 | gs = ax.get_gridspec() |
| 200 | if gs is not None: |
| 201 | if hasattr(gs, 'get_topmost_subplotspec'): |
| 202 | # This is needed for colorbar gridspec layouts. |
| 203 | # This is probably OK because this whole logic tree |
| 204 | # is for when the user is doing simple things with the |
| 205 | # add_subplot command. For complicated layouts |
| 206 | # like subgridspecs the proper gridspec is passed in... |
| 207 | gs = gs.get_topmost_subplotspec().get_gridspec() |
| 208 | if gs.get_geometry() == (nrows, ncols): |
| 209 | return gs |
| 210 | # else gridspec not found: |
| 211 | return GridSpec(nrows, ncols, figure=figure) |
| 212 | |
| 213 | def __getitem__(self, key): |
| 214 | """Create and return a `.SubplotSpec` instance.""" |
no test coverage detected