diff --git a/doc/api/api_changes/2015-01-19_reorder_axes_get_children.rst b/doc/api/api_changes/2015-01-19_reorder_axes_get_children.rst new file mode 100644 index 000000000000..49d2da6a8d81 --- /dev/null +++ b/doc/api/api_changes/2015-01-19_reorder_axes_get_children.rst @@ -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`. diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index dd7f46ea9905..80187471f6b9 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -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: @@ -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)) @@ -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):