Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pixelated animations in Matplotlib

I've been using Matplotlib's animation facility to produce animated figures. I've noticed a problem which is particularly noticeable for animations with a large number of frames, which is that the quality of the figures deteriorates very quickly resulting in pixelated - blurry looking output.

Examples:

Messy grid lines Messy grid lines

pixelated output pixilated output

I've been rendering animations using

import matplotlib
matplotlib.use("Agg")

anim = animation.FuncAnimation(fig, ..., blit=False)
mywriter = animation.FFMpegWriter(fps=15)
anim.save("path.mp4", writer=mywriter)

I've tried using blit=True/False but haven't noticed much difference.

Matplotlib version: 1.4.2. System: Mac 10.10

like image 689
osnoz Avatar asked Feb 28 '15 18:02

osnoz


1 Answers

This is what worked for me.

You can change the bitrate while creating the writer instance

import matplotlib.animation as animation

anim = animation.FuncAnimation(fig, ...)

FFMpegWriter = animation.writers['ffmpeg']
metadata = dict(title='Movie Test', artist='Matplotlib',
                comment='Movie support!')

# Change the video bitrate as you like and add some metadata.
writer = FFMpegWriter(fps=15, bitrate=1000, metadata=metadata)

Then you can save your video.

anim.save("path.mp4", writer=mywriter)

Hope it helps

like image 150
mrcl Avatar answered Sep 18 '22 17:09

mrcl