In animated plots, the order at wich artists are drawn is determined by their position in the sequence returned by the animation function, despite their own "zorder" property.
This might be an effect of the blitting, if it is turned on. Try turning
off blitting, as that will force a redraw of each artist object at their
respective zorder.
It is slightly better to just tweak the visibility in the init function.
Tagging this for 1.4.x, but I think this behavior should be documented, but not changed. With blitting the animated artists must be on top of all the other artists in the axes so we are already treating the animated artists differently.
Activity
tacaswell commented on Apr 8, 2014
Can you provide a minimal example which demonstrates this?
WeatherGod commented on Apr 8, 2014
This might be an effect of the blitting, if it is turned on. Try turning
off blitting, as that will force a redraw of each artist object at their
respective zorder.
On Tue, Apr 8, 2014 at 10:12 AM, Thomas A Caswell
notifications@github.comwrote:
sebtoun commented on Apr 8, 2014
Here is a code sample showing the issue (indeed turning off blitting restores a correct behaviour): blue circle should be in front of red one
# -*- coding: utf-8 -*- import matplotlib.pyplot as plt import matplotlib.animation as animation from math import sin, pi fig = plt.figure() ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2), aspect='equal') circle_fg = plt.Circle((-0.5,0),1,color='b') circle_fg.set_zorder(2) ax.add_artist(circle_fg) circle_bg = plt.Circle((0.5,0),1,color='r') circle_bg.set_zorder(1) ax.add_artist(circle_bg) def init(): circle_fg.radius = 0 circle_bg.radius = 0 return circle_fg, circle_bg def animate(i): circle_fg.radius = 1 circle_bg.radius = 1 circle_fg.center = (-0.5, -sin(i*2*pi/50)) circle_bg.center = (0.5, sin(i*2*pi/50)) # order in return sequence determine draw order with blit=True, # zorder property seems to be ignored return circle_fg, circle_bg ani = animation.FuncAnimation(fig, animate, 200, interval=40, blit=True, init_func=init) plt.show()By the way, is there a cleaner way to define init function ? I alway have to put dubious code in it in order to get a clean empty background...
tacaswell commented on Jun 29, 2014
It is slightly better to just tweak the visibility in the init function.
Tagging this for 1.4.x, but I think this behavior should be documented, but not changed. With blitting the animated artists must be on top of all the other artists in the axes so we are already treating the animated artists differently.