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

Class SubplotSpec

lib/matplotlib/gridspec.py:531–738  ·  view source on GitHub ↗

The location of a subplot in a `GridSpec`. .. note:: Likely, you will never instantiate a `SubplotSpec` yourself. Instead, you will typically obtain one from a `GridSpec` using item-access. Parameters ---------- gridspec : `~matplotlib.gridspec.GridSpec`

Source from the content-addressed store, hash-verified

529
530
531class SubplotSpec:
532 """
533 The location of a subplot in a `GridSpec`.
534
535 .. note::
536
537 Likely, you will never instantiate a `SubplotSpec` yourself. Instead,
538 you will typically obtain one from a `GridSpec` using item-access.
539
540 Parameters
541 ----------
542 gridspec : `~matplotlib.gridspec.GridSpec`
543 The GridSpec, which the subplot is referencing.
544 num1, num2 : int
545 The subplot will occupy the *num1*-th cell of the given
546 *gridspec*. If *num2* is provided, the subplot will span between
547 *num1*-th cell and *num2*-th cell **inclusive**.
548
549 The index starts from 0.
550 """
551 def __init__(self, gridspec, num1, num2=None):
552 self._gridspec = gridspec
553 self.num1 = num1
554 self.num2 = num2
555
556 def __repr__(self):
557 return (f"{self.get_gridspec()}["
558 f"{self.rowspan.start}:{self.rowspan.stop}, "
559 f"{self.colspan.start}:{self.colspan.stop}]")
560
561 @staticmethod
562 def _from_subplot_args(figure, args):
563 """
564 Construct a `.SubplotSpec` from a parent `.Figure` and either
565
566 - a `.SubplotSpec` -- returned as is;
567 - one or three numbers -- a MATLAB-style subplot specifier.
568 """
569 if len(args) == 1:
570 arg, = args
571 if isinstance(arg, SubplotSpec):
572 return arg
573 elif not isinstance(arg, Integral):
574 raise ValueError(
575 f"Single argument to subplot must be a three-digit "
576 f"integer, not {arg!r}")
577 try:
578 rows, cols, num = map(int, str(arg))
579 except ValueError:
580 raise ValueError(
581 f"Single argument to subplot must be a three-digit "
582 f"integer, not {arg!r}") from None
583 elif len(args) == 3:
584 rows, cols, num = args
585 else:
586 raise _api.nargs_error("subplot", takes="1 or 3", given=len(args))
587
588 gs = GridSpec._check_gridspec_exists(figure, rows, cols)

Callers 1

__getitem__Method · 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…