Note
Click here to download the full example code
20. Animation
Create an animation.
8 import numpy as np
9 import matplotlib.pyplot as plt
10 import matplotlib.animation as animation
11
12 # Adapted from
13 # https://matplotlib.org/gallery/animation/basic_example.html
14
15
16 def _update_line(num):
17 line.set_data(data[..., :num])
18 return line,
19
20
21 fig, ax = plt.subplots()
22 data = np.random.RandomState(0).rand(2, 25)
23 line, = ax.plot([], [], 'r-')
24 ax.set(xlim=(0, 1), ylim=(0, 1))
25 ani = animation.FuncAnimation(fig, _update_line, 25, interval=100, blit=True)
26
27 plt.show()
Total running time of the script: ( 0 minutes 2.538 seconds)