From 664ab81e8156c39efe6d79cb30634c1d8013911e Mon Sep 17 00:00:00 2001 From: jdollichon Date: Sat, 2 Jun 2018 19:13:23 +0200 Subject: [PATCH 1/3] Sorting drawn artists by their zorder when blitting --- lib/matplotlib/animation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 32c9a8eca0a1..4e8832f270c8 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1723,7 +1723,7 @@ def _draw_frame(self, framedata): # Call the func with framedata and args. If blitting is desired, # func needs to return a sequence of any artists that were modified. - self._drawn_artists = self._func(framedata, *self._args) + self._drawn_artists = sorted(self._func(framedata, *self._args), key=lambda x: x.get_zorder()) if self._blit: if self._drawn_artists is None: raise RuntimeError('The animation function must return a ' From c1004850d0ec1f415f181506cabc073a200934ce Mon Sep 17 00:00:00 2001 From: jdollichon Date: Sun, 3 Jun 2018 09:02:28 +0200 Subject: [PATCH 2/3] Pep-8 compliant line length --- lib/matplotlib/animation.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 4e8832f270c8..eb1c8827132e 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1723,7 +1723,8 @@ def _draw_frame(self, framedata): # Call the func with framedata and args. If blitting is desired, # func needs to return a sequence of any artists that were modified. - self._drawn_artists = sorted(self._func(framedata, *self._args), key=lambda x: x.get_zorder()) + self._drawn_artists = sorted(self._func(framedata, *self._args), + key=lambda x: x.get_zorder()) if self._blit: if self._drawn_artists is None: raise RuntimeError('The animation function must return a ' From ce9737d5286b17a7dc86dfb9aa4c28db8f36c1cc Mon Sep 17 00:00:00 2001 From: jdollichon Date: Sun, 3 Jun 2018 09:50:27 +0200 Subject: [PATCH 3/3] Added API change note and docs --- .../next_api_changes/2018-06-03-JD-funcani-zorder.rst | 9 +++++++++ lib/matplotlib/animation.py | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 doc/api/next_api_changes/2018-06-03-JD-funcani-zorder.rst diff --git a/doc/api/next_api_changes/2018-06-03-JD-funcani-zorder.rst b/doc/api/next_api_changes/2018-06-03-JD-funcani-zorder.rst new file mode 100644 index 000000000000..95e52e7db727 --- /dev/null +++ b/doc/api/next_api_changes/2018-06-03-JD-funcani-zorder.rst @@ -0,0 +1,9 @@ +`.FuncAnimation` now draws artists according to their zorder when blitting +-------------------------------------------------------------------------- + +`.FuncAnimation` now draws artists returned by the user- +function according to their zorder when using blitting, +instead of using the order in which they are being passed. +However, note that only zorder of passed artists will be +respected, as they are drawn on top of any existing artists +(see `#11369 `_). \ No newline at end of file diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index eb1c8827132e..84d3b6d14db0 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -1607,8 +1607,10 @@ def init_func() -> iterable_of_artists: of frames is completed. Defaults to ``True``. blit : bool, optional - Controls whether blitting is used to optimize drawing. Defaults - to ``False``. + Controls whether blitting is used to optimize drawing. Note: when using + blitting any animated artists will be drawn according to their zorder. + However, they will be drawn on top of any previous artists, regardless + of their zorder. Defaults to ``False``. ''' def __init__(self, fig, func, frames=None, init_func=None, fargs=None,