From b1db6102467fb399ce6684e5935b16988382c9bf Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 11:21:35 -0600 Subject: [PATCH 1/6] Fix get_children order to match draw order --- lib/matplotlib/axes/_base.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index dd7f46ea9905..c5448253687f 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -3170,22 +3170,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): From a449d92c718e7cd785822009f5f718989503d0af Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 19:35:25 -0600 Subject: [PATCH 2/6] Add an api change document --- .../api_changes/2015-01-19_reorder_axes_get_children.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 doc/api/api_changes/2015-01-19_reorder_axes_get_children.rst 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`. From 1bacd6396f6f780584061d256380cdd6bf6fdb68 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 19:35:33 -0600 Subject: [PATCH 3/6] Change draw to pull from get_children --- lib/matplotlib/axes/_base.py | 41 +++++++++++++++--------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index c5448253687f..dd928c77b2ea 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,25 @@ 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()] + 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()] dsu.sort(key=itemgetter(0)) From 7ef11abd83ccea89f0d9602f53dd0557c10001b8 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 21:22:00 -0600 Subject: [PATCH 4/6] Handle visibility of the x and y axis --- lib/matplotlib/axes/_base.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index dd928c77b2ea..a8ea42a5e4f1 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2006,6 +2006,10 @@ def draw(self, renderer=None, inframe=False): else: self.xaxis.set_zorder(2.5) self.yaxis.set_zorder(2.5) + else: + artists.remove(self.xaxis) + artists.remove(self.yaxis) + if inframe: artists.remove(self.title) artists.remove(self._left_title) From 93b0679d22889e867fdbf1ed669d30d9b67e539d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 21:43:54 -0600 Subject: [PATCH 5/6] Guard against removing animated images --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index a8ea42a5e4f1..331389bbc648 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2028,7 +2028,7 @@ def draw(self, renderer=None, inframe=False): dsu = [(a.zorder, a) for a in artists] else: dsu = [(a.zorder, a) for a in artists - if not a.get_animated()] + if (not a.get_animated() and not a in self.images)] dsu.sort(key=itemgetter(0)) From 84e8e0d4aa72e000d1a4b584867cbc2b8229fad3 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Mon, 19 Jan 2015 21:45:06 -0600 Subject: [PATCH 6/6] Fix the animate image guard --- lib/matplotlib/axes/_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 331389bbc648..80187471f6b9 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2028,7 +2028,7 @@ def draw(self, renderer=None, inframe=False): dsu = [(a.zorder, a) for a in artists] else: dsu = [(a.zorder, a) for a in artists - if (not a.get_animated() and not a in self.images)] + if (not a.get_animated() or a in self.images)] dsu.sort(key=itemgetter(0))