Putting arrowheads on vectors in matplotlib's 3d plot

前端 未结 2 1858
萌比男神i
萌比男神i 2020-12-02 10:46

I plotted the eigenvectors of some 3D-data and was wondering if there is currently (already) a way to put arrowheads on the lines? Would be awesome if someone has a tip for

2条回答
  •  情话喂你
    2020-12-02 11:23

    Another option: you can also use the plt.quiver function, which allows you to produce arrow vectors pretty easily without any extra imports or classes.

    To replicate your example, you would replace:

    for v in eig_vec:
        ax.plot([mean_x, v[0]], [mean_y, v[1]], [mean_z, v[2]], color='red', alpha=0.8, lw=3)
    

    with:

    for v in eig_vec:
        ax.quiver(
            mean_x, mean_y, mean_z, # <-- starting point of vector
            v[0] - mean_x, v[1] - mean_y, v[2] - mean_z, # <-- directions of vector
            color = 'red', alpha = .8, lw = 3,
        )
    

提交回复
热议问题