How to set the image resolution for animations?

前端 未结 2 1636
一个人的身影
一个人的身影 2021-02-20 00:52

how can I set the resolution of an animation saved as mp4 movie with \"matplotlib.animation\" module?

On the web I only found examples using \"animation.FuncAnimation\".

2条回答
  •  抹茶落季
    2021-02-20 01:40

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

    You can set the dpi in the save argument, and before you save it, set the size of the figure with

    fig.set_size_inches(w_in_inches, h_in_inches, True). 
    

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

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

    You may need do upgrade to a newer version of mpl (debian is great because it is so conservative and awful because it is so conservative) from source.

提交回复
热议问题