Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 33e4bb0

Browse files
committed
Add example that manually uses a movie writer object.
1 parent 1644a4e commit 33e4bb0

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

examples/animation/moviewriter.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This example uses a MovieWriter directly to grab individual frames and
2+
# write them to a file. This avoids any event loop integration, but has
3+
# the advantage of working with even the Agg backend. This is not recommended
4+
# for use in an interactive setting.
5+
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
import matplotlib.animation as manimation
9+
10+
FFMpegWriter = manimation.writers['ffmpeg']
11+
writer = FFMpegWriter(fps=15)
12+
13+
fig = plt.figure()
14+
l, = plt.plot([], [], 'k-o')
15+
16+
plt.xlim(-5, 5)
17+
plt.ylim(-5, 5)
18+
19+
x0,y0 = 0, 0
20+
21+
with writer.saving(fig, "writer_test.mp4", 100):
22+
for i in range(100):
23+
x0 += 0.1 * np.random.randn()
24+
y0 += 0.1 * np.random.randn()
25+
l.set_data(x0, y0)
26+
writer.grab_frame()
27+

0 commit comments

Comments
 (0)