python - 为什么这个动态更新的散点图没有做任何事情?
问题描述
我正在尝试找到一种动态更新 3d 散点图的方法。我发现这篇关于动态更新的 2d 图的帖子,我能够让代码在我的机器上运行而无需任何调整。但是当试图让它适应 3d 情节时,我遇到了一些麻烦。这是我的代码:
import numpy as np
import matplotlib.animation as ani
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig, sa, sb, l, a, b, z, x = None, None, None, None, None, None, None, None
devices = []
a=2
def animate(i):
global a
x.append(a)
y.append(a)
z.append(a)
sc.set_offsets(np.c_[x,y,z])
a += 1
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim3d(0, 10)
ax.set_ylim3d(0, 10)
ax.set_zlim3d(0, 10)
plt.subplots_adjust(left=0.25, bottom=0.25)
x = [1]
y = [1]
z = [1]
sc = ax.scatter(x,y,z)
animation = ani.FuncAnimation(fig, animate, frames=2, interval=100)
plt.show()
当我运行它时,会弹出一个 3d 绘图,其中绘制了一个点并且没有动画。任何人都知道这段代码有什么问题吗?谢谢!
解决方案
推荐阅读
- sql - 有没有更优雅的方式来编写这个 Oracle SQL 查询?
- google-cloud-platform - GCP 中的 HTTP 端点
- internet-explorer-11 - fls.doubleclick.net 仅在 IE11 中下载缓慢
- python - 谷歌 SMTP 在发送邮件时出错
- python-3.x - 在 python 中使用 pandas 打印名为 12/12/12 的列
- google-cloud-platform - 从 Cloud Source 启动 Dataproc PySpark 作业
- java - Java 8 将简单的列表转换为地图
- c++ - 了解使用堆栈实现队列的递归调用机制
- c++ - 从资源视图访问对话框的问题
- python - python 3.7 list.pop 按名称而不是索引