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

Class _AxesStack

lib/matplotlib/figure.py:70–115  ·  view source on GitHub ↗

Helper class to track Axes in a figure. Axes are tracked both in the order in which they have been added (``self._axes`` insertion/iteration order) and in the separate "gca" stack (which is the index to which they map in the ``self._axes`` dict).

Source from the content-addressed store, hash-verified

68
69
70class _AxesStack:
71 """
72 Helper class to track Axes in a figure.
73
74 Axes are tracked both in the order in which they have been added
75 (``self._axes`` insertion/iteration order) and in the separate "gca" stack
76 (which is the index to which they map in the ``self._axes`` dict).
77 """
78
79 def __init__(self):
80 self._axes = {} # Mapping of Axes to "gca" order.
81 self._counter = itertools.count()
82
83 def as_list(self):
84 """List the Axes that have been added to the figure."""
85 return [*self._axes] # This relies on dict preserving order.
86
87 def remove(self, a):
88 """Remove the Axes from the stack."""
89 self._axes.pop(a)
90
91 def bubble(self, a):
92 """Move an Axes, which must already exist in the stack, to the top."""
93 if a not in self._axes:
94 raise ValueError("Axes has not been added yet")
95 self._axes[a] = next(self._counter)
96
97 def add(self, a):
98 """Add an Axes to the stack, ignoring it if already present."""
99 if a not in self._axes:
100 self._axes[a] = next(self._counter)
101
102 def current(self):
103 """Return the active Axes, or None if the stack is empty."""
104 return max(self._axes, key=self._axes.__getitem__, default=None)
105
106 def __getstate__(self):
107 return {
108 **vars(self),
109 "_counter": max(self._axes.values(), default=0)
110 }
111
112 def __setstate__(self, state):
113 next_counter = state.pop('_counter')
114 vars(self).update(state)
115 self._counter = itertools.count(next_counter)
116
117
118class FigureBase(Artist):

Callers 1

__init__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…