How to set zdata for a Line3D object in Python Matplotlib

I would like to update a figure containing a Line3D object. To do this I would like to update the data for the line and then redraw the canvas.

For a Line2D object, the x and y values can be updated using "set_xdata" and "set_ydata". How do I set the zdata? Just using "set_zdata" gives an error..

1 answer

  • answered 2017-10-11 10:02 Crimson

    A Line3D object contains the method "set_3d_properties(zs=0, zdir='z')". This can be used to set the zdata:

    #plot figure with line
    f=pyplot.figure()
    ax=f.add_subplot(111, projection='3d')
    mylines=ax.plot(xs,ys,zs)
    
    #update figure with new x and z data
    mylines[0].set_xdata(newxs)
    mylines[0].set_3d_properties(newzs)
    f.canvas.draw()