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

Skip to content

Sorting drawn artists by their zorder when blitting using FuncAnimation #11370

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 3 commits into from
Jul 5, 2018
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
9 changes: 9 additions & 0 deletions doc/api/next_api_changes/2018-06-03-JD-funcani-zorder.rst
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/matplotlib/matplotlib/issues/11369>`_).
9 changes: 6 additions & 3 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1723,7 +1725,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 = 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 '
Expand Down