Add all subplots specified by this `GridSpec` to its parent figure. See `.Figure.subplots` for detailed documentation.
(self, *, sharex=False, sharey=False, squeeze=True,
subplot_kw=None)
| 248 | return SubplotSpec(self, num1, num2) |
| 249 | |
| 250 | def subplots(self, *, sharex=False, sharey=False, squeeze=True, |
| 251 | subplot_kw=None): |
| 252 | """ |
| 253 | Add all subplots specified by this `GridSpec` to its parent figure. |
| 254 | |
| 255 | See `.Figure.subplots` for detailed documentation. |
| 256 | """ |
| 257 | |
| 258 | figure = self.figure |
| 259 | |
| 260 | if figure is None: |
| 261 | raise ValueError("GridSpec.subplots() only works for GridSpecs " |
| 262 | "created with a parent figure") |
| 263 | |
| 264 | if not isinstance(sharex, str): |
| 265 | sharex = "all" if sharex else "none" |
| 266 | if not isinstance(sharey, str): |
| 267 | sharey = "all" if sharey else "none" |
| 268 | |
| 269 | _api.check_in_list(["all", "row", "col", "none", False, True], |
| 270 | sharex=sharex, sharey=sharey) |
| 271 | if subplot_kw is None: |
| 272 | subplot_kw = {} |
| 273 | # don't mutate kwargs passed by user... |
| 274 | subplot_kw = subplot_kw.copy() |
| 275 | |
| 276 | # Create array to hold all Axes. |
| 277 | axarr = np.empty((self._nrows, self._ncols), dtype=object) |
| 278 | for row in range(self._nrows): |
| 279 | for col in range(self._ncols): |
| 280 | shared_with = {"none": None, "all": axarr[0, 0], |
| 281 | "row": axarr[row, 0], "col": axarr[0, col]} |
| 282 | subplot_kw["sharex"] = shared_with[sharex] |
| 283 | subplot_kw["sharey"] = shared_with[sharey] |
| 284 | axarr[row, col] = figure.add_subplot( |
| 285 | self[row, col], **subplot_kw) |
| 286 | |
| 287 | # turn off redundant tick labeling |
| 288 | if sharex in ["col", "all"]: |
| 289 | for ax in axarr.flat: |
| 290 | ax._label_outer_xaxis(skip_non_rectangular_axes=True) |
| 291 | if sharey in ["row", "all"]: |
| 292 | for ax in axarr.flat: |
| 293 | ax._label_outer_yaxis(skip_non_rectangular_axes=True) |
| 294 | |
| 295 | if squeeze: |
| 296 | # Discarding unneeded dimensions that equal 1. If we only have one |
| 297 | # subplot, just return it instead of a 1-element array. |
| 298 | return axarr.item() if axarr.size == 1 else axarr.squeeze() |
| 299 | else: |
| 300 | # Returned axis array will be always 2-d, even if nrows=ncols=1. |
| 301 | return axarr |
| 302 | |
| 303 | |
| 304 | class GridSpec(GridSpecBase): |
nothing calls this directly
no test coverage detected