我想知道如何FuncAnimation在 Python 3 中保存 a 的最后一张图像。这是一些代码:
import matplotlib.animation
from mpl_toolkits.mplot3d import Axes3D
ani = matplotlib.animation.FuncAnimation(fig, _update_2d_graph, frames=9, interval=600, repeat_delay=5000, blit=False)
ani.save(output_dir, writer="imagemagick")
其中_update_2d_graph是一个函数,根据帧数提供不同的点偏移量:
def _update_2d_graph(num):
x_updated = np.hstack((pos_gt.x[:num].tolist(),pos_pred.x[:num].tolist()))
y_updated = np.hstack((pos_gt.y[:num].tolist(),pos_pred.y[:num].tolist()))
paths_gt = []
paths_ped = []
for i in range(num):
marker_gt = mmarkers.MarkerStyle('o')
marker_ped = mmarkers.MarkerStyle('x')
path_gt = marker_gt.get_path().transformed(marker_gt.get_transform())
path_ped = marker_ped.get_path().transformed(marker_ped.get_transform())
paths_gt.append(path_gt)
paths_ped.append(path_ped)
graph._paths = np.concatenate([paths_gt, paths_ped])
graph.set_facecolors(np.concatenate([colors[:num], colors[:num]]))
graph.set_edgecolors(np.concatenate([colors[:num], colors[:num]]))
graph.set_offsets(np.hstack((y_updated[:, np.newaxis], x_updated[:, np.newaxis])))
而不是保存整个动画(例如作为 .gif 文件),我想保存动画的最后一个时间步的 .png。 是否可以访问动画对象中的最后一帧?
我不想调用,_update_2d_graph(9)因为这个调用已经被动画对象执行了,我也不想通过另一个FuncAnimation调用重新迭代整个 9 帧。
慕姐4208626
相关分类