How to set image resolution for animation?

How can I set the resolution of an animation saved as an mp4 movie using the matplotlib.animation module?

I found examples on the Internet using "animation.FuncAnimation". For example, a good tutorial from http://jakevdp.github.com/blog/2012/08/18/matplotlib-animation-tutorial/ :

anim = animation.FuncAnimation(fig, animate, init_func=init, frames=200, interval=20, blit=True) anim.save('basic_animation.mp4', fps=30, extra_args=['-vcodec', 'libx264']) 

From the matplotlib.animation module link, I found the "animation.Animation.save" method that provides the "dpi" argument, but I don’t know how to use this function correctly.

 matplotlib.animation.Animation.save(filename, writer=None, fps=None, dpi=None, codec=None, bitrate=None, extra_args=None, metadata=None, extra_anim=None) 

A small sample code may be helpful.

Many thanks.

Johannes

PS: By the way, how can you insert python code with sytax highlighting?

+8
matplotlib animation
source share
2 answers

You can control the resolution in a round way. Resolution, figure size and dpi are not independent, if you know two of them, then the third is fixed.

You can set the dpi in the save argument, and before saving it, set the size of the shape with

 fig.set_size_inches(h_in_inches, w_in_inches, True). 

Your resolution is then dpi * h_in_inches X dpi * w_in_inches .

 dpi = 100 writer = animation.writers['ffmpeg'](fps=30) ani.save('test.mp4',writer=writer,dpi=dpi) 

You may need to upgrade to a newer version of mpl (debian is excellent because it is so conservative and terrible because it is so conservative) from the source code.

+5
source share

bitrate - a parameter used to determine the quality of the film. The higher the value you set, the higher the quality of the movie.

+2
source share

All Articles