kwplot.mpl_plotnums module¶
Defines the kwplot.mpl_plotnums.PlotNums class to help manage a grid
of subplot numbers.
- class kwplot.mpl_plotnums.PlotNums(nRows=None, nCols=None, nSubplots=None, start=0)[source]¶
Bases:
objectConvinience class for dealing with plot numberings (pnums)
This is useful in the case where you want a certain number of subplots, but you might swap the order in which those subplots are called. This class introduces the idea of either getting the “next” subplot, or getting one at a specific instance. The total number of subplots can be modified in just a single place in the code (the arguments to the
PlotNumsconstructor) instead of each instance where you would specify a pnum normally.Example
>>> import ubelt as ub >>> pnum_ = PlotNums(nRows=2, nCols=2) >>> # Indexable >>> print(pnum_[0]) (2, 2, 1) >>> # Iterable >>> print(ub.repr2(list(pnum_), nl=0, nobr=1)) (2, 2, 1), (2, 2, 2), (2, 2, 3), (2, 2, 4) >>> # Callable (iterates through a default iterator) >>> print(pnum_()) (2, 2, 1) >>> print(pnum_()) (2, 2, 2)