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

Skip to content

Fix Axes get_children order to match draw order #4014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/api/api_changes/2015-01-19_reorder_axes_get_children.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Reordered `Axes.get_children`
`````````````````````````````

The artist order returned by `Axes.get_children` did not
match the one used by `Axes.draw`. They now use the same
order, as `Axes.draw` now calls `Axes.get_children`.
61 changes: 29 additions & 32 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1988,20 +1988,16 @@ def draw(self, renderer=None, inframe=False):
else:
self.apply_aspect()

artists = []

artists.extend(self.collections)
artists.extend(self.patches)
artists.extend(self.lines)
artists.extend(self.texts)
artists.extend(self.artists)
artists = self.get_children()
artists.remove(self.patch)

# the frame draws the edges around the axes patch -- we
# decouple these so the patch can be in the background and the
# frame in the foreground. Do this before drawing the axis
# objects so that the spine has the opportunity to update them.
if self.axison and self._frameon:
artists.extend(six.itervalues(self.spines))
if not (self.axison and self._frameon):
for spine in six.itervalues(self.spines):
artists.remove(spine)

if self.axison and not inframe:
if self._axisbelow:
Expand All @@ -2010,28 +2006,29 @@ def draw(self, renderer=None, inframe=False):
else:
self.xaxis.set_zorder(2.5)
self.yaxis.set_zorder(2.5)
artists.extend([self.xaxis, self.yaxis])
if not inframe:
artists.append(self.title)
artists.append(self._left_title)
artists.append(self._right_title)
artists.extend(self.tables)
if self.legend_ is not None:
artists.append(self.legend_)

if self.figure.canvas.is_saving():
dsu = [(a.zorder, a) for a in artists]
else:
dsu = [(a.zorder, a) for a in artists
if not a.get_animated()]
artists.remove(self.xaxis)
artists.remove(self.yaxis)

if inframe:
artists.remove(self.title)
artists.remove(self._left_title)
artists.remove(self._right_title)

# add images to dsu if the backend support compositing.
# otherwise, does the manaul compositing without adding images to dsu.
if len(self.images) <= 1 or renderer.option_image_nocomposite():
dsu.extend([(im.zorder, im) for im in self.images])
_do_composite = False
else:
_do_composite = True
for im in self.images:
artists.remove(im)

if self.figure.canvas.is_saving():
dsu = [(a.zorder, a) for a in artists]
else:
dsu = [(a.zorder, a) for a in artists
if (not a.get_animated() or a in self.images)]

dsu.sort(key=itemgetter(0))

Expand Down Expand Up @@ -3170,22 +3167,22 @@ def set_cursor_props(self, *args):
def get_children(self):
"""return a list of child artists"""
children = []
children.append(self.xaxis)
children.append(self.yaxis)
children.extend(self.lines)
children.extend(self.collections)
children.extend(self.patches)
children.extend(self.lines)
children.extend(self.texts)
children.extend(self.tables)
children.extend(self.artists)
children.extend(self.images)
if self.legend_ is not None:
children.append(self.legend_)
children.extend(self.collections)
children.extend(six.itervalues(self.spines))
children.append(self.xaxis)
children.append(self.yaxis)
children.append(self.title)
children.append(self._left_title)
children.append(self._right_title)
children.extend(self.tables)
children.extend(self.images)
if self.legend_ is not None:
children.append(self.legend_)
children.append(self.patch)
children.extend(six.itervalues(self.spines))
return children

def contains(self, mouseevent):
Expand Down