animation - 如何设置动画的图像分辨率?

标签 animation matplotlib

如何使用“matplotlib.animation”模块设置保存为 mp4 影片的动画的分辨率?

在网上我只找到了使用“animation.FuncAnimation”的示例。例如来自 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'])

从 matplotlib.animation 模块引用中,我发现“animation.Animation.save”方法提供了“dpi”参数,但我不知道如何正确应用此函数

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

一个小示例代码可能会有所帮助。

非常感谢。

约翰内斯

PS:顺便问一下,如何使用 sytax-highlighting 插入 Python 代码?

最佳答案

您可以通过迂回方式控制分辨率。分辨率、图形大小和 dpi 并不都是独立的,如果你知道其中两个,那么第三个就固定了。

您可以在保存参数中设置dpi,并在保存之前使用

设置图形的大小
fig.set_size_inches(w_in_inches, h_in_inches, True). 

您的分辨率为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)

您可能需要从源代码升级到较新版本的 mpl(debian 很棒,因为它非常保守,也很糟糕,因为它非常保守)。

关于animation - 如何设置动画的图像分辨率?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14666439/

相关文章:

css - 如何在动画后将元素永久保持在 100% - C

matplotlib - matplotlib滴答厚度

python - 导入错误 : No module named six [Windows]

javascript - 使用jquery隐藏带有动画的div

javascript - "Drop"<li> 在 Bootstrap 菜单中悬停

python - 向 matplotlib 颜色图图例添加垂直标签

python - 用于 Python 的 XGBoost : plot importance

python - matplotlib 图表 - 创建水平条形图

iOS "erase"使用 CAShapeLayer 动画绘图

javascript - 我的 mootools 幻灯片代码有什么问题?