Matplotlib中的像素化动画 [英] Pixelated animations in Matplotlib
问题描述
我一直在使用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.
示例:
凌乱的网格线
像素化输出
我一直在使用
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,但没有发现太大差异。
I've tried using blit=True/False but haven't noticed much difference.
Matplotlib版本: 1.4.2。系统:Mac 10.10
Matplotlib version: 1.4.2. System: Mac 10.10
推荐答案
这对我有用。
您可以在创建编写器实例时更改比特率
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)
希望有帮助
这篇关于Matplotlib中的像素化动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!