1"""
2==================
3Animated line plot
4==================
5
6"""
7
8import numpy as np
9import matplotlib.pyplot as plt
10import matplotlib.animation as animation
11
12fig, ax = plt.subplots()
13
14x = np.arange(0, 2*np.pi, 0.01)
15line, = ax.plot(x, np.sin(x))
16
17
18def init():  # only required for blitting to give a clean slate.
19    line.set_ydata([np.nan] * len(x))
20    return line,
21
22
23def animate(i):
24    line.set_ydata(np.sin(x + i / 100))  # update the data.
25    return line,
26
27
28ani = animation.FuncAnimation(
29    fig, animate, init_func=init, interval=2, blit=True, save_count=50)
30
31# To save the animation, use e.g.
32#
33# ani.save("movie.mp4")
34#
35# or
36#
37# from matplotlib.animation import FFMpegWriter
38# writer = FFMpegWriter(fps=15, metadata=dict(artist='Me'), bitrate=1800)
39# ani.save("movie.mp4", writer=writer)
40
41plt.show()
42