I'm trying to do some animation with FuncAnimation. Instead of using .set_data() I'm using this alternative structure:
def update_plot(frame, y, plot):
plot[0].remove()
plot[0] = ax.scatter(np.sin(y[frame,0]),-np.cos(y[frame,0]), color = "orange")
#(...)
# Initial
plot = [ax.scatter(np.sin(y[0,0]),-np.cos(y[0,0]), color = "orange")]
# Animate
animate = animation.FuncAnimation(fig, update_plot, nmax, fargs = (y, plot))
animate.save('pendulum.gif',writer='imagemagick')
This works well. However, if I use ax.plot() instead of ax.scatter():
def update_plot(frame, y, plot):
plot[0].remove()
plot[0] = ax.plot(np.sin(y[frame,0]),-np.cos(y[frame,0]),'o', color = "orange")
# Initial
plot = [ax.plot(np.sin(y[0,0]),-np.cos(y[0,0]),'o', color = "orange")]
# Animate
animate = animation.FuncAnimation(fig, update_plot, nmax, fargs = (y, plot))
animate.save('pendulum.gif',writer='imagemagick')
the code fails because of the plot[0].remove() with the following error:
remove() takes exactly one argument (0 given)
Why is that the case?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…