How to plot 2d math vectors with matplotlib?

后端 未结 2 564
梦毁少年i
梦毁少年i 2020-12-13 05:14

How can we plot 2D math vectors with matplotlib? Does anyone have an example or suggestion about that?

I have a couple of vectors stored as 2D nu

2条回答
  •  遥遥无期
    2020-12-13 05:28

    The suggestion in the comments by halex is correct, you want to use quiver (doc), but you need to tweak the properties a bit.

    import numpy as np
    import matplotlib.pyplot as plt
    
    soa = np.array([[0, 0, 3, 2], [0, 0, 1, 1], [0, 0, 9, 9]])
    X, Y, U, V = zip(*soa)
    plt.figure()
    ax = plt.gca()
    ax.quiver(X, Y, U, V, angles='xy', scale_units='xy', scale=1)
    ax.set_xlim([-1, 10])
    ax.set_ylim([-1, 10])
    plt.draw()
    plt.show()
    

提交回复
热议问题