【发布时间】:2021-03-30 18:53:27
【问题描述】:
我在尝试为 3D 绘图设置动画时遇到问题。为了给出一个想法,假设我从每个视频帧中收集了 3 个数据点。假设我的视频仅包含 5 帧。
例如,我提取了如下坐标;
x = [[1.0,1.2,1.3], [1.2,1.1,1.3], [1.3,1.2,1.0], [1.2,1.1,1.4], [1.2,1.4,1.1]]
y = [[2.0,2.2,2.3], [2.2,2.1,2.3], [2.3,2.2,2.0], [2.2,2.1,2.4], [2.2,2.4,2.1]]
z = [[3.0,3.2,3.3], [3.2,3.1,3.3], [3.3,3.2,3.0], [3.2,3.1,3.4], [2.2,2.4,2.1]]
len(x) = len(y) = len(z) = 5 (# of frames)
这意味着在1st 框架中,我的坐标是(1.0, 2.0, 3.0), (1.2, 2.2, 3.2) & (1.3,2.3, 3.3),
在2nd 框架中(1.2,2.2,3.2), (1.1,2.1,3.1) & (1.3,2.3, 3.3) 等等。
我在 Jupyter 笔记本中尝试如下;但没有成功。
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
fig = plt.figure()
ax = p3.Axes3D(fig)
timesteps = 100
border = 2
ax.set_xlim3d([-border, border])
ax.set_ylim3d([-border, border])
ax.set_zlim3d([-border, border])
def animate(i):
ax.set_xlim3d([-border, border])
ax.set_ylim3d([-border, border])
ax.set_zlim3d([-border, border])
ax.scatter(x[i],y[i],z[i])
anim = animation.FuncAnimation(fig, animate, frames=timesteps, interval=1, blit=False, repeat=False)
anim
【问题讨论】:
标签: python python-3.x matplotlib animation