How to customize the animation frame rate, speed, and repetitions

To disable the ability of the animation, set repeat to False, as shown in the following code:

# Repeat, pause after final frame
nums = np.arange(0,10,0.1)
sin, = plt.plot(nums, np.sin(nums))
frames=np.arange(0,2*np.pi,0.1)
def update(i):
sin.set_ydata(np.sin(nums+i))
FuncAnimation(plt.gcf(), update, frames=frames, interval=50,
repeat_delay=2e3)

By setting repeat to False, we get to loop through the frames array. Then, the animation will halt:

To pause the repetition of the animation, use the repeat_delay argument. By using this argument (repeat_delay=2e3), we can see that it will rotate through the animation, pause for two seconds, and repeat again.

This is a nice way of stopping the animation to let the viewer know that you're going back to the beginning to repeat the animation:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset