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

Skip to content

Commit fc1f2ff

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 c931e85 commit fc1f2ff

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
@@ -1105,7 +1105,6 @@ def cla(self):
11051105

11061106
self._gridOn = mpl.rcParams['axes.grid']
11071107
self._children = []
1108-
self.artists = []
11091108
self._mouseover_set = _OrderedSet()
11101109
self.child_axes = []
11111110
self._current_image = None # strictly for pyplot via _sci, _gci
@@ -1177,6 +1176,14 @@ def cla(self):
11771176

11781177
self.stale = True
11791178

1179+
@property
1180+
def artists(self):
1181+
return tuple(
1182+
a for a in self._children
1183+
if not isinstance(a, (
1184+
mcoll.Collection, mimage.AxesImage, mlines.Line2D,
1185+
mpatches.Patch, mtable.Table, mtext.Text)))
1186+
11801187
@property
11811188
def collections(self):
11821189
return tuple(a for a in self._children
@@ -1914,7 +1921,7 @@ def has_data(self):
19141921

19151922
def add_artist(self, a):
19161923
"""
1917-
Add an `~.Artist` to the axes, and return the artist.
1924+
Add an `~.Artist` to the Axes; return the artist.
19181925
19191926
Use `add_artist` only for artists for which there is no dedicated
19201927
"add" method; and if necessary, use a method such as `update_datalim`
@@ -1926,8 +1933,8 @@ def add_artist(self, a):
19261933
``ax.transData``.
19271934
"""
19281935
a.axes = self
1929-
self.artists.append(a)
1930-
a._remove_method = self.artists.remove
1936+
self._children.append(a)
1937+
a._remove_method = self._children.remove
19311938
self._set_artist_props(a)
19321939
a.set_clip_path(self.patch)
19331940
self.stale = True
@@ -4078,7 +4085,6 @@ def get_children(self):
40784085
# docstring inherited.
40794086
return [
40804087
*self._children,
4081-
*self.artists,
40824088
*self.spines.values(),
40834089
*self._get_axis_list(),
40844090
self.title, self._left_title, self._right_title,

lib/mpl_toolkits/axes_grid1/parasite_axes.py

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

230230
def draw(self, renderer):
231231

232-
orig_artists = list(self.artists)
233232
orig_children_len = len(self._children)
234233

235234
if hasattr(self, "get_axes_locator"):
@@ -249,10 +248,9 @@ def draw(self, renderer):
249248
ax.apply_aspect(rect)
250249
images, artists = ax.get_images_artists()
251250
self._children.extend(images)
252-
self.artists.extend(artists)
251+
self._children.extend(artists)
253252

254253
super().draw(renderer)
255-
self.artists = orig_artists
256254
self._children = self._children[:orig_children_len]
257255

258256
def cla(self):

0 commit comments

Comments
 (0)