1import numpy as np
2import matplotlib.pyplot as plt
3from matplotlib.animation import FuncAnimation
4
5fig, ax = plt.subplots()
6xdata, ydata = [], []
7ln, = plt.plot([], [], 'ro')
8
9def init():
10 ax.set_xlim(0, 2*np.pi)
11 ax.set_ylim(-1, 1)
12 return ln,
13
14def update(frame):
15 xdata.append(frame)
16 ydata.append(np.sin(frame))
17 ln.set_data(xdata, ydata)
18 return ln,
19
20ani = FuncAnimation(fig, update, frames=np.linspace(0, 2*np.pi, 128),
21 init_func=init, blit=True)
22plt.show()
23
1import matplotlib.pyplot as plt
2from matplotlib import cm
3import numpy as np
4from celluloid import Camera
5
6numpoints = 10
7points = np.random.random((2, numpoints))
8colors = cm.rainbow(np.linspace(0, 1, numpoints))
9camera = Camera(plt.figure())
10for _ in range(100):
11 points += 0.1 * (np.random.random((2, numpoints)) - .5)
12 plt.scatter(*points, c=colors, s=100)
13 camera.snap()
14anim = camera.animate(blit=True)
15anim.save('scatter.mp4')
16