A simple Python module for recording matplotlib animation
It can generate a matplotlib animation movie (mp4, gif, etc.)
This tool use "convert" command of ImageMagick.
-
ImageMagic (newest version, maybe no need to install ffmpeg by use the new version of imagemagick)
-
sudo apt-get install imagemagick (make matplotrecorder.py work normally when save .gif file) (old version)
-
install ffmpeg (google how to install and this is required if you want to save video such as .mp4 by matplotrecorder.py) (In matplotrecorder.py use ffmpeg command save .mp4 or other videro. Use convert command to save .gif.)
Call save_frame() at each animation iteration,
And then, call savemovie() for movie generation.
A sample code:
import matplotrecorder
print("A sample recording start")
import math
time = range(50)
x1 = [math.cos(t / 10.0) for t in time]
y1 = [math.sin(t / 10.0) for t in time]
x2 = [math.cos(t / 10.0) + 2 for t in time]
y2 = [math.sin(t / 10.0) + 2 for t in time]
for ix1, iy1, ix2, iy2 in zip(x1, y1, x2, y2):
plt.plot(ix1, iy1, "xr")
plt.plot(ix2, iy2, "xb")
plt.axis("equal")
plt.pause(0.1)
matplotrecorder.save_frame() # save each frame
# generate movie
matplotrecorder.save_movie("animation.mp4", 0.1)
# matplotrecorder.save_movie("animation.gif", 0.1) #gif is ok.
MIT
Atsushi Sakai (@Atsushi_twi)