所以我有一个3D图形,它是一个散点图,通过遍历数据框来更新点。我有它添加一个新的点.1秒。这是我的代码:
ion()
fig = figure()
ax = fig.add_subplot(111, projection='3d')
count = 0
plotting = True
while plotting:
df2 = df.ix[count]
count += 1
xs = df2['x.mean']
ys = df2['y.mean']
zs = df2['z.mean']
t = df2['time']
ax.scatter(xs, ys, zs)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
ax.set_title(t)
draw()
pause(0.01)
if count > 50:
plotting = False
ioff()
show()
如何让它只显示实时更新图表上的新点。现在它从一个点开始,然后添加另一个点,直到图表上总共有50个点。
所以我想要的是,图表上永远不会有多个点,只是在迭代过程中要改变这一点。我怎么能这样做?
答案 0 :(得分:2)
ion()
fig = figure()
ax = fig.add_subplot(111, projection='3d')
count = 0
plotting = True
# doesn't need to be in loop
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
lin = None
while plotting:
df2 = df.ix[count]
count += 1
xs = df2['x.mean']
ys = df2['y.mean']
zs = df2['z.mean']
t = df2['time']
if lin is not None:
lin.remove()
lin = ax.scatter(xs, ys, zs)
ax.set_title(t)
draw()
pause(0.01)
if count > 50:
plotting = False
ioff()
show()
原则上你也可以使用普通plot
而不是scatter
来更新循环中的数据,但3D更新可能会很糟糕/可能需要稍微戳一下内部。