Matplotlib中的像素化动画

时间:2015-02-28 18:12:27

标签: python animation matplotlib scipy

我一直在使用Matplotlib的动画工具来制作动画人物。我注意到一个问题,对于有大量帧的动画尤其明显,这就是数字的质量很快恶化,导致像素化 - 模糊的输出。

示例:

凌乱的网格线 Messy grid lines

像素化输出 pixilated output

我一直在使用

渲染动画
import matplotlib
matplotlib.use("Agg")

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

我尝试过使用blit = True / False,但没有注意到很多不同。

Matplotlib版本:1.4.2。系统:Mac 10.10

1 个答案:

答案 0 :(得分:5)

这对我有用。

您可以在创建编写器实例时更改比特率

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)

然后您可以保存您的视频。

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

希望有所帮助