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 32c9a8eca0a1..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, @@ -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 '