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

Skip to content

Commit 300e4c9

Browse files
authored
Merge pull request #11370 from jdollichon/issue-#11369
Sorting drawn artists by their zorder when blitting using FuncAnimation
2 parents 17df397 + ce9737d commit 300e4c9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`.FuncAnimation` now draws artists according to their zorder when blitting
2+
--------------------------------------------------------------------------
3+
4+
`.FuncAnimation` now draws artists returned by the user-
5+
function according to their zorder when using blitting,
6+
instead of using the order in which they are being passed.
7+
However, note that only zorder of passed artists will be
8+
respected, as they are drawn on top of any existing artists
9+
(see `#11369 <https://github.com/matplotlib/matplotlib/issues/11369>`_).

lib/matplotlib/animation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1607,8 +1607,10 @@ def init_func() -> iterable_of_artists:
16071607
of frames is completed. Defaults to ``True``.
16081608
16091609
blit : bool, optional
1610-
Controls whether blitting is used to optimize drawing. Defaults
1611-
to ``False``.
1610+
Controls whether blitting is used to optimize drawing. Note: when using
1611+
blitting any animated artists will be drawn according to their zorder.
1612+
However, they will be drawn on top of any previous artists, regardless
1613+
of their zorder. Defaults to ``False``.
16121614
16131615
'''
16141616
def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
@@ -1723,7 +1725,8 @@ def _draw_frame(self, framedata):
17231725

17241726
# Call the func with framedata and args. If blitting is desired,
17251727
# func needs to return a sequence of any artists that were modified.
1726-
self._drawn_artists = self._func(framedata, *self._args)
1728+
self._drawn_artists = sorted(self._func(framedata, *self._args),
1729+
key=lambda x: x.get_zorder())
17271730
if self._blit:
17281731
if self._drawn_artists is None:
17291732
raise RuntimeError('The animation function must return a '

0 commit comments

Comments
 (0)