Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d5e1e1a

Browse filesBrowse files
committed
Move Axes.images into hidden children attribute.
The images can still be accessed via a read-only property, but now are combined with lines, patches, tables and texts for sorting and drawing purposes.
1 parent 380c9f2 commit d5e1e1a
Copy full SHA for d5e1e1a

File tree

Expand file treeCollapse file tree

2 files changed

+28
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+28
-14
lines changed

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+12-8Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,7 +1148,6 @@ def cla(self):
11481148
self._gridOn = mpl.rcParams['axes.grid']
11491149
self._children = []
11501150
self.artists = []
1151-
self.images = []
11521151
self._mouseover_set = _OrderedSet()
11531152
self.child_axes = []
11541153
self._current_image = None # strictly for pyplot via _sci, _gci
@@ -1221,6 +1220,11 @@ def cla(self):
12211220

12221221
self.stale = True
12231222

1223+
@property
1224+
def images(self):
1225+
return tuple(a for a in self._children
1226+
if isinstance(a, mimage.AxesImage))
1227+
12241228
@property
12251229
def lines(self):
12261230
return tuple(a for a in self._children if isinstance(a, mlines.Line2D))
@@ -2002,13 +2006,13 @@ def add_collection(self, collection, autolim=True):
20022006

20032007
def add_image(self, image):
20042008
"""
2005-
Add an `~.AxesImage` to the axes' images; return the image.
2009+
Add an `~.AxesImage` to the Axes; return the image.
20062010
"""
20072011
self._set_artist_props(image)
20082012
if not image.get_label():
2009-
image.set_label('_image%d' % len(self.images))
2010-
self.images.append(image)
2011-
image._remove_method = self.images.remove
2013+
image.set_label(f'_child{len(self._children)}')
2014+
self._children.append(image)
2015+
image._remove_method = self._children.remove
20122016
self.stale = True
20132017
return image
20142018

@@ -2814,8 +2818,9 @@ def draw(self, renderer=None, inframe=False):
28142818
artists.remove(self._right_title)
28152819

28162820
if not self.figure.canvas.is_saving():
2817-
artists = [a for a in artists
2818-
if not a.get_animated() or a in self.images]
2821+
artists = [
2822+
a for a in artists
2823+
if not a.get_animated() or isinstance(a, mimage.AxesImage)]
28192824
artists = sorted(artists, key=attrgetter('zorder'))
28202825

28212826
# rasterize artists with negative zorder
@@ -4250,7 +4255,6 @@ def get_children(self):
42504255
*self.spines.values(),
42514256
*self._get_axis_list(),
42524257
self.title, self._left_title, self._right_title,
4253-
*self.images,
42544258
*self.child_axes,
42554259
*([self.legend_] if self.legend_ is not None else []),
42564260
self.patch,

‎lib/mpl_toolkits/axes_grid1/parasite_axes.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/parasite_axes.py
+16-6Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from matplotlib import _api, cbook
44
import matplotlib.artist as martist
5+
import matplotlib.image as mimage
56
import matplotlib.transforms as mtransforms
67
from matplotlib.axes import subplot_class_factory
78
from matplotlib.transforms import Bbox
@@ -24,9 +25,18 @@ def cla(self):
2425
self._get_lines = self._parent_axes._get_lines
2526

2627
def get_images_artists(self):
27-
artists = {a for a in self.get_children() if a.get_visible()}
28-
images = {a for a in self.images if a.get_visible()}
29-
return list(images), list(artists - images)
28+
artists = []
29+
images = []
30+
31+
for a in self.get_children():
32+
if not a.get_visible():
33+
continue
34+
if isinstance(a, mimage.AxesImage):
35+
images.append(a)
36+
else:
37+
artists.append(a)
38+
39+
return images, artists
3040

3141
def pick(self, mouseevent):
3242
# This most likely goes to Artist.pick (depending on axes_class given
@@ -204,7 +214,7 @@ def _get_legend_handles(self, legend_handler_map=None):
204214
def draw(self, renderer):
205215

206216
orig_artists = list(self.artists)
207-
orig_images = list(self.images)
217+
orig_children_len = len(self._children)
208218

209219
if hasattr(self, "get_axes_locator"):
210220
locator = self.get_axes_locator()
@@ -222,12 +232,12 @@ def draw(self, renderer):
222232
for ax in self.parasites:
223233
ax.apply_aspect(rect)
224234
images, artists = ax.get_images_artists()
225-
self.images.extend(images)
235+
self._children.extend(images)
226236
self.artists.extend(artists)
227237

228238
super().draw(renderer)
229239
self.artists = orig_artists
230-
self.images = orig_images
240+
self._children = self._children[:orig_children_len]
231241

232242
def cla(self):
233243
for ax in self.parasites:

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.