gpt4 book ai didi

python - Matplotlib 中的像素化动画

转载 作者:太空狗 更新时间:2023-10-29 20:27:25 25 4
gpt4 key购买 nike

我一直在使用 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

最佳答案

这对我有用。

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

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)

希望对你有帮助

关于python - Matplotlib 中的像素化动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28785118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com