Skip to content

Commit 12231a0

Browse files
committed
Add example that creates writer class and passes it for saving.
1 parent 1c602f2 commit 12231a0

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Same as basic_example, but writes files using a single MovieWriter instance
2+
# without putting on screen
3+
import numpy as np
4+
import matplotlib
5+
matplotlib.use("Agg")
6+
import matplotlib.pyplot as plt
7+
import matplotlib.animation as animation
8+
9+
def update_line(num, data, line):
10+
line.set_data(data[...,:num])
11+
return line,
12+
13+
# Set up formatting for the movie files
14+
Writer = animation.writers['ffmpeg']
15+
writer = Writer(fps=15, metadata=dict(artist='Me'), bitrate=1800)
16+
17+
18+
fig1 = plt.figure()
19+
20+
data = np.random.rand(2, 25)
21+
l, = plt.plot([], [], 'r-')
22+
plt.xlim(0, 1)
23+
plt.ylim(0, 1)
24+
plt.xlabel('x')
25+
plt.title('test')
26+
line_ani = animation.FuncAnimation(fig1, update_line, 25, fargs=(data, l),
27+
interval=50, blit=True)
28+
line_ani.save('lines.mp4', writer=writer)
29+
30+
fig2 = plt.figure()
31+
32+
x = np.arange(-9, 10)
33+
y = np.arange(-9, 10).reshape(-1, 1)
34+
base = np.hypot(x, y)
35+
ims = []
36+
for add in np.arange(15):
37+
ims.append((plt.pcolor(x, y, base + add, norm=plt.Normalize(0, 30)),))
38+
39+
im_ani = animation.ArtistAnimation(fig2, ims, interval=50, repeat_delay=3000,
40+
blit=True)
41+
im_ani.save('im.mp4', writer=writer)

0 commit comments

Comments
 (0)