Home > front end >  Python quiver angles issue: What is the difference between angles="uv" and angles="xy
Python quiver angles issue: What is the difference between angles="uv" and angles="xy

Time:09-17

I have a vector field that I want to plot correctly. When I use quiver as is, it seems to be outputting the correct plot:

enter image description here

However, if I follow the guidelines to have quiver scale and show the correct angles of the vectors, as given here enter image description here

Does anybody knows why?

Here is the code:

import numpy as np
import matplotlib.pyplot as plt

xx = np.array([[0. , 0.2, 0.4, 0.6, 0.8, 1. ],
       [0. , 0.2, 0.4, 0.6, 0.8, 1. ],
       [0. , 0.2, 0.4, 0.6, 0.8, 1. ],
       [0. , 0.2, 0.4, 0.6, 0.8, 1. ],
       [0. , 0.2, 0.4, 0.6, 0.8, 1. ],
       [0. , 0.2, 0.4, 0.6, 0.8, 1. ]])    

yy = np.array([[-200. , -200. , -200. , -200. , -200. , -200. ],
   [-144.6, -144.6, -144.6, -144.6, -144.6, -144.6],
   [ -89.2,  -89.2,  -89.2,  -89.2,  -89.2,  -89.2],
   [ -33.8,  -33.8,  -33.8,  -33.8,  -33.8,  -33.8],
   [  21.6,   21.6,   21.6,   21.6,   21.6,   21.6],
   [  77. ,   77. ,   77. ,   77. ,   77. ,   77. ]])


dx = np.array([[ 6.18291908e-09,  3.70076924e-06,  3.42538903e-06,
            -4.38426006e-07, -2.55227640e-06,  6.18291908e-09],
           [ 2.17018678e-06,  2.51500956e-04,  1.73477082e-04,
            -1.23855846e-04, -2.29881121e-04,  2.17018678e-06],
           [ 2.44470726e-05,  3.79715107e-03,  2.49497711e-03,
            -2.05506466e-03, -3.60106480e-03,  2.44470726e-05],
           [ 2.87699956e-04,  3.56327893e-02,  2.23694354e-02,
            -2.17573718e-02, -3.50990203e-02,  2.87699956e-04],
           [ 2.13917741e-03,  1.07630739e-01,  1.09098114e-01,
            -1.73049517e-01, -1.15168685e-01,  2.13917741e-03],
           [ 3.13827774e-04, -3.87236380e-02, -4.33945841e-02,
             7.12401001e-02,  3.91662321e-02,  3.13827774e-04]])

dy = np.array([[0.24105279, 0.24104844, 0.24104251, 0.24104319, 0.24104954,
        0.24105279],
       [0.2409212 , 0.24103392, 0.24123878, 0.24125286, 0.24105669,
        0.2409212 ],
       [0.23870441, 0.24127457, 0.24563927, 0.24579267, 0.24151955,
        0.23870441],
       [0.21110992, 0.24513396, 0.30153966, 0.30228133, 0.24619877,
        0.21110992],
       [0.07941149, 0.14922776, 0.70945221, 0.67353021, 0.12818932,
        0.07941149],
       [0.07717276, 0.04937775, 0.18100361, 0.16734886, 0.03621946,
        0.07717276]])

# PLOT 1 (Correct one)

plt.figure(1, dpi = 300)
plt.quiver(xx, yy, dx, dy)
plt.title("Plot 1")
plt.show()

# PLOT 2 (Something is wrong her)
# Inspiration from: https://stackoverflow.com/questions/36534381/understanding-matplotlibs-quiver-plotting

plt.figure(2, dpi = 300)
plt.quiver(xx, yy, dx, dy, angles="xy", scale_units='xy', scale=1)
plt.title("Plot 2")
plt.show()

EDIT: Please have a look at the dx, dy data: The dx data is smaller than the dy data, therefore, the vectors should always point upward and not sight-wise.

CodePudding user response:

According to the Using angles=xy

Another option for drawing vector fields would be using streamplot, which may produce a result that meets your demand.

  • Related