make matplotlib draw() only show new point

后端 未结 1 1548
眼角桃花
眼角桃花 2021-01-17 02:28

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


        
相关标签:
1条回答
  • 2021-01-17 03:18
    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()
    

    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.

    0 讨论(0)
提交回复
热议问题