Matplotlib quiver plotting with constant arrow size

后端 未结 1 1393
南方客
南方客 2021-01-20 08:25

I\'m trying to plot a simple quiver plot (e.g. as in the matplotlib gallery: http://matplotlib.org/examples/pylab_examples/quiver_demo.html), although I don\'t want the auto

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-20 08:58

    Changing scale won't work for this. You need to normalize the vectors, e.g.

    X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
    U = np.cos(X)
    V = np.sin(Y)
    
    # Normalize the arrows:
    U = U / np.sqrt(U**2 + V**2);
    V = V / np.sqrt(U**2 + V**2);
    
    
    plt.figure()
    plt.title('Normalized arrows')
    Q = plt.quiver(X, Y, U, V, units='width')
    qk = plt.quiverkey(Q, 0.9, 0.9, 2, r'$2 \frac{m}{s}$', labelpos='E',
                       coordinates='figure')
    

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