使matplotlib draw()仅显示新点 [英] make matplotlib draw() only show new point

查看:126
本文介绍了使matplotlib draw()仅显示新点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个3D图形,它是一个散点图,通过浏览数据框来更新一个点。我让它每0.1秒增加一个新点。这是我的代码:

So I have a 3D graph that is a scatterplot updating a point by going through a dataframe. I have it add a new point ever .1 seconds. Here is my code:

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个点。

How can I get it to only show the new point on the live-updated graph. Right now it starts with one point and then adds another and another until there is a total of 50 points on the graph.

所以我想要的是永远不会图上有多个点,并且随着迭代不断地改变该点。我该怎么做?

So what I want is for there never to be more than one point on the graph and just have that point be changing as it iterates through. How can I do this?

推荐答案

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()

原则上,您也可以使用普通的绘图代替 scatter 并在循环中更新数据,但是3D更新可能会很不稳定,可能需要稍微戳一下内部。

In principle you can also use a normal plot instead of scatter and update the data in the loop, but the 3D updating can be wonky/may require poking at the internals a bit.

这篇关于使matplotlib draw()仅显示新点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆