MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / GridSpecFromSubplotSpec

Class GridSpecFromSubplotSpec

lib/matplotlib/gridspec.py:471–528  ·  view source on GitHub ↗

GridSpec whose subplot layout parameters are inherited from the location specified by a given SubplotSpec.

Source from the content-addressed store, hash-verified

469
470
471class GridSpecFromSubplotSpec(GridSpecBase):
472 """
473 GridSpec whose subplot layout parameters are inherited from the
474 location specified by a given SubplotSpec.
475 """
476 def __init__(self, nrows, ncols,
477 subplot_spec,
478 wspace=None, hspace=None,
479 height_ratios=None, width_ratios=None):
480 """
481 Parameters
482 ----------
483 nrows, ncols : int
484 Number of rows and number of columns of the grid.
485 subplot_spec : SubplotSpec
486 Spec from which the layout parameters are inherited.
487 wspace, hspace : float, optional
488 See `GridSpec` for more details. If not specified default values
489 (from the figure or rcParams) are used.
490 height_ratios : array-like of length *nrows*, optional
491 See `GridSpecBase` for details.
492 width_ratios : array-like of length *ncols*, optional
493 See `GridSpecBase` for details.
494 """
495 self._wspace = wspace
496 self._hspace = hspace
497 if isinstance(subplot_spec, SubplotSpec):
498 self._subplot_spec = subplot_spec
499 else:
500 raise TypeError(
501 "subplot_spec must be type SubplotSpec, "
502 "usually from GridSpec, or axes.get_subplotspec.")
503 self.figure = self._subplot_spec.get_gridspec().figure
504 super().__init__(nrows, ncols,
505 width_ratios=width_ratios,
506 height_ratios=height_ratios)
507
508 def get_subplot_params(self, figure=None):
509 """Return a dictionary of subplot layout parameters."""
510 hspace = (self._hspace if self._hspace is not None
511 else figure.subplotpars.hspace if figure is not None
512 else mpl.rcParams["figure.subplot.hspace"])
513 wspace = (self._wspace if self._wspace is not None
514 else figure.subplotpars.wspace if figure is not None
515 else mpl.rcParams["figure.subplot.wspace"])
516
517 figbox = self._subplot_spec.get_position(figure)
518 left, bottom, right, top = figbox.extents
519
520 return SubplotParams(left=left, right=right,
521 bottom=bottom, top=top,
522 wspace=wspace, hspace=hspace)
523
524 def get_topmost_subplotspec(self):
525 """
526 Return the topmost `.SubplotSpec` instance associated with the subplot.
527 """
528 return self._subplot_spec.get_topmost_subplotspec()

Callers 1

subgridspecMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…