Writing Matplotlib plot/movie sequences with lossy .avi/.mp4

Matplotlib on any platform can use Ffmpeg, Avconv or Mencoder to directly write compressed (lossy, small file size) plot sequences. Lossless movie creation with Matplotlib is also possible.

The default “auto” bitrate makes excessively compressed, blocky movies. Override the default auto-bitrate with the following snippet:

Writer = anim.writers['ffmpeg']
writer = Writer(fps=15, codec='mpeg4', bitrate=1e6)
with writer.saving(fg, fn,100):