python - 有没有办法将 matplotlib 的 FuncAnimation 向前或向后移动一帧?
问题描述
现在,FuncAnimation 只能分别使用 event_source.start() 和 event_source.stop() 启动和停止,那么有没有办法在保持 blitting 的同时将 matplotlib FuncAnimation 向前移动一帧或向后移动一帧?
下面显示的示例是 FuncAnimation 的 matplotlib 示例。理想情况下,最好有一个按钮可以将动画向前或向后移动一帧。
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
def f(x, y):
return np.sin(x) + np.cos(y)
x = np.linspace(0, 2 * np.pi, 120)
y = np.linspace(0, 2 * np.pi, 100).reshape(-1, 1)
im = plt.imshow(f(x, y), animated=True)
def updatefig(*args):
global x, y
x += np.pi / 15.
y += np.pi / 20.
im.set_array(f(x, y))
return im,
ani = animation.FuncAnimation(fig, updatefig, interval=50, blit=True)
plt.show()
解决方案
推荐阅读
- .net - 运行 .net 项目时出现 HTTP 错误 500.19 - 内部服务器错误
- javascript - 当用户使用 Svelte 和 Sapper 单击按钮时获取新页面
- outlook - 如何在邮箱outlook中限制用户的读取权限
- android - Xamarin Forms 的图像控制问题。图像未渲染
- tensorflow - 如何在图层中设置自定义权重?
- r - 如何使用 dplyr R 中的汇总计算一列并同时添加几列
- webpack - webpack 将默认导入解析为命名导入
- python - 使用图像作为参数从 c# 调用 python 脚本
- bash - 需要提取所需的输出
- python - 打开现有工作簿的问题