Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0133d86

Browse files
committed
Turn _localaxes into a plain list.
gca() order is only tracked by the toplevel axstack; _localaxes can be a plain list, just tracking the order in which axes were added to the figure.
1 parent 68d6b79 commit 0133d86

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def make_layoutgrids(fig, layoutgrids):
167167
layoutgrids = make_layoutgrids(sfig, layoutgrids)
168168

169169
# for each axes at the local level add its gridspec:
170-
for ax in fig._localaxes.as_list():
170+
for ax in fig._localaxes:
171171
if hasattr(ax, 'get_subplotspec'):
172172
gs = ax.get_subplotspec().get_gridspec()
173173
layoutgrids = make_layoutgrids_gs(layoutgrids, gs)
@@ -298,7 +298,7 @@ def make_layout_margins(layoutgrids, fig, renderer, *, w_pad=0, h_pad=0,
298298
hspace=hspace, wspace=wspace)
299299
layoutgrids[sfig].parent.edit_outer_margin_mins(margins, ss)
300300

301-
for ax in fig._localaxes.as_list():
301+
for ax in fig._localaxes:
302302
if not hasattr(ax, 'get_subplotspec') or not ax.get_in_layout():
303303
continue
304304

@@ -561,7 +561,7 @@ def reposition_axes(layoutgrids, fig, renderer, *,
561561
w_pad=w_pad, h_pad=h_pad,
562562
wspace=wspace, hspace=hspace)
563563

564-
for ax in fig._localaxes.as_list():
564+
for ax in fig._localaxes:
565565
if not hasattr(ax, 'get_subplotspec') or not ax.get_in_layout():
566566
continue
567567

lib/matplotlib/figure.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def __init__(self, **kwargs):
203203
self.figure = self
204204
# list of child gridspecs for this figure
205205
self._gridspecs = []
206-
self._localaxes = _AxesStack() # track all axes and current axes
206+
self._localaxes = [] # track all axes
207207
self.artists = []
208208
self.lines = []
209209
self.patches = []
@@ -229,7 +229,7 @@ def _get_draw_artists(self, renderer):
229229
artists = sorted(
230230
(artist for artist in artists if not artist.get_animated()),
231231
key=lambda artist: artist.get_zorder())
232-
for ax in self._localaxes.as_list():
232+
for ax in self._localaxes:
233233
locator = ax.get_axes_locator()
234234
if locator:
235235
pos = locator(ax, renderer)
@@ -294,7 +294,7 @@ def get_children(self):
294294
"""Get a list of artists contained in the figure."""
295295
return [self.patch,
296296
*self.artists,
297-
*self._localaxes.as_list(),
297+
*self._localaxes,
298298
*self.lines,
299299
*self.patches,
300300
*self.texts,
@@ -776,7 +776,8 @@ def add_subplot(self, *args, **kwargs):
776776
def _add_axes_internal(self, ax, key):
777777
"""Private helper for `add_axes` and `add_subplot`."""
778778
self._axstack.add(ax)
779-
self._localaxes.add(ax)
779+
if ax not in self._localaxes:
780+
self._localaxes.append(ax)
780781
self.sca(ax)
781782
ax._remove_method = self.delaxes
782783
# this is to support plt.subplot's re-selection logic
@@ -2081,14 +2082,14 @@ def axes(self):
20812082
List of Axes in the SubFigure. You can access and modify the Axes
20822083
in the SubFigure through this list.
20832084
2084-
Do not modify the list itself. Instead, use `~.SubFigure.add_axes`,
2085+
Modifying this list has no effect. Instead, use `~.SubFigure.add_axes`,
20852086
`~.SubFigure.add_subplot` or `~.SubFigure.delaxes` to add or remove an
20862087
Axes.
20872088
20882089
Note: The `.SubFigure.axes` property and `~.SubFigure.get_axes` method
20892090
are equivalent.
20902091
"""
2091-
return self._localaxes.as_list()
2092+
return self._localaxes[:]
20922093

20932094
get_axes = axes.fget
20942095

0 commit comments

Comments
 (0)