matplotlib - matplotlib.animation 可以在将帧保存到文件时显示帧吗?
问题描述
当我执行animator.save()
时,plt.show()
在保存过程完成之前不显示绘图。我有一个 Python 代码,它使用动画库来显示通过网络接收的数据,我想记录已经显示的数据。有没有办法实现这种行为?
解决方案
您可以将图形直接保存在更新函数中:
fig, ax = plt.subplots()
l, = ax.plot(range(10),[0]*10,'r-')
ax.set_ylim(0,1)
def animate(i):
y = np.random.random(size=(10,))
l.set_ydata(y)
fig.savefig(f'test_{i}.png')
return l,
ani = animation.FuncAnimation(fig, animate, frames=10)
推荐阅读
- python - 如何访问 Python 创建的字典
- nativescript - Nativescript - 按下通知时如何将应用程序置于前台
- javascript - 制表符不是函数
- ruby - 如何获取简单 Sequel Dataset 对象的表名?
- here-api - HereMaps API 端点返回带有换行符的 json
- laravel - Laravel 邮政编码查询
- c# - 使用参数调用存储过程以返回列表
- sql - 数据大小与查询执行
- advanced-custom-fields - ACF 中继器字段仅显示一行
- liferay - 如果 liferay 放置 30 分钟然后更新,则会出现 CSRF 令牌错误