Skip to content

Commit 333cce9

Browse files
committed
Move Axes.artists into hidden children attribute.
The artists can still be accessed via a read-only property, but now are combined with collections, images, lines, patches, tables and texts for sorting and drawing purposes. Additionally, anything added using `Axes.add_artist` will now appear in the correct type sublist, and may not appear in `Axes.artists` if it matches any of the other lists. There are two test image changes, both of which have to do with `bxp` and its `patch_artist=True` option. This uses a `Patch` with `Axes.add_artist` instead of `Axes.plot` and so used to appear in different order. This change now makes `patch_artist=True` and `path_artist=False` order the same way, since there's no special grouping.
1 parent 94da8c9 commit 333cce9

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,6 @@ def cla(self):
12321232

12331233
self._gridOn = mpl.rcParams['axes.grid']
12341234
self._children = []
1235-
self.artists = []
12361235
self._mouseover_set = _OrderedSet()
12371236
self.child_axes = []
12381237
self._current_image = None # strictly for pyplot via _sci, _gci
@@ -1305,6 +1304,14 @@ def cla(self):
13051304

13061305
self.stale = True
13071306

1307+
@property
1308+
def artists(self):
1309+
return tuple(
1310+
a for a in self._children
1311+
if not isinstance(a, (
1312+
mcoll.Collection, mimage.AxesImage, mlines.Line2D,
1313+
mpatches.Patch, mtable.Table, mtext.Text)))
1314+
13081315
@property
13091316
def collections(self):
13101317
return tuple(a for a in self._children
@@ -2035,7 +2042,7 @@ def has_data(self):
20352042

20362043
def add_artist(self, a):
20372044
"""
2038-
Add an `~.Artist` to the axes, and return the artist.
2045+
Add an `~.Artist` to the Axes; return the artist.
20392046
20402047
Use `add_artist` only for artists for which there is no dedicated
20412048
"add" method; and if necessary, use a method such as `update_datalim`
@@ -2047,8 +2054,8 @@ def add_artist(self, a):
20472054
``ax.transData``.
20482055
"""
20492056
a.axes = self
2050-
self.artists.append(a)
2051-
a._remove_method = self.artists.remove
2057+
self._children.append(a)
2058+
a._remove_method = self._children.remove
20522059
self._set_artist_props(a)
20532060
a.set_clip_path(self.patch)
20542061
self.stale = True
@@ -4349,7 +4356,6 @@ def get_children(self):
43494356
# docstring inherited.
43504357
return [
43514358
*self._children,
4352-
*self.artists,
43534359
*self.spines.values(),
43544360
*self._get_axis_list(),
43554361
self.title, self._left_title, self._right_title,
128 Bytes
Loading
78 Bytes
Loading

lib/mpl_toolkits/axes_grid1/parasite_axes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ def _get_legend_handles(self, legend_handler_map=None):
213213

214214
def draw(self, renderer):
215215

216-
orig_artists = list(self.artists)
217216
orig_children_len = len(self._children)
218217

219218
if hasattr(self, "get_axes_locator"):
@@ -233,10 +232,9 @@ def draw(self, renderer):
233232
ax.apply_aspect(rect)
234233
images, artists = ax.get_images_artists()
235234
self._children.extend(images)
236-
self.artists.extend(artists)
235+
self._children.extend(artists)
237236

238237
super().draw(renderer)
239-
self.artists = orig_artists
240238
self._children = self._children[:orig_children_len]
241239

242240
def cla(self):

0 commit comments

Comments
 (0)