【问题标题】:3D plot animation in PythonPython中的3D绘图动画
【发布时间】: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


    【解决方案1】:

    我能够使用以下链接解决它:see here。 如果将来有人需要,我会在这里发布。

    【讨论】:

    • 将解决方案放在这里并将其标记为已回答以供将来参考
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-25
    • 1970-01-01
    • 2012-09-28
    • 2021-10-12
    • 1970-01-01
    • 1970-01-01
    • 2021-07-21
    相关资源
    最近更新 更多