A

#### A_Mlt

##### Guest

Code:

```
import numpy as np
import matplotlib.pyplot as plt
import math
#Data
N=5
diff_X=np.array([[-0.000125 , -0.00013 , -0.000125 , -0.00012308, -0.00012692],
[-0.00012615, -0.000125 , -0.00013154, -0.00012308, -0.00012 ],
[-0.00012423, -0.00011808, -0.00011577, -0.00012769, -0.00012923],
[-0.00012115, -0.00012308, -0.00011962, -0.00012538, -0.00012308],
[-0.00012808, -0.00013077, -0.00012808, -0.00012038, -0.00012885]])
diff_Y=np.array([[5.69230769e-05, 6.19230769e-05, 6.76923077e-05, 5.88461538e-05,
6.34615385e-05],
[5.73076923e-05, 6.92307692e-05, 6.19230769e-05, 6.61538462e-05,
6.34615385e-05],
[5.53846154e-05, 7.30769231e-05, 6.50000000e-05, 6.92307692e-05,
6.23076923e-05],
[6.57692308e-05, 5.57692308e-05, 6.50000000e-05, 6.38461538e-05,
6.76923077e-05],
[6.38461538e-05, 6.57692308e-05, 6.80769231e-05, 6.53846154e-05,
6.34615385e-05]])
#Computation of the matrix diff and the corresponding angles (arctan2)
for i in range(0,N):
for j in range(0,N):
diff[i][j] = math.sqrt(diff_X[i][j]**2+diff_Y[i][j]**2)
arrow_diff[i][j] = np.arctan2(diff_Y[i][j],diff_X[i][j])
j=j+1
i=i+1
#Plot of the map
fig, ax = plt.subplots()
im = ax.imshow(diff, interpolation='bicubic',
cmap=cm.inferno,
origin='upper',
vmax=diff.max(), vmin=diff.min())
# vmax=sum_max, vmin=sum_min)
X, Y = np.meshgrid(np.arange(0, N, 1), np.arange(0, N, 1))
U = np.cos(X*diff_X)
V = np.sin(Y*diff_Y)
Q = ax.quiver(X, Y, U, V, arrow_diff, units='width')
qk = ax.quiverkey(Q, X, Y, 0.2, labelpos='E',
coordinates='figure')
```

However, this is what I get:

I can't figure out how to get the arrows pointing in the right direction for each coordinates and also how to adapt their size to be proportionnal to their argument

`arctan2(diff_Y[i][j],diff_X[i][j])`

.I would expect all the arrows pointing in one direction and with a size more or less constant. I tried changing the arguments of quiver and quiverkey but it doesn't work.

<p>I plot a matrix 'diff' (quadratique sum of the input matrix diff_X and diff_Y) as a colored map using imshow and I would like to display arrows showing the corresponding angle arctan2(diff_Y/diff_X) for each coordinates. This is my program so far:</p>

<pre><code>import numpy as np

import matplotlib.pyplot as plt

import math

#Data

N=5

diff_X=np.array([[-0.000125 , -0.00013 , -0.000125 , -0.00012308, -0.00012692],

[-0.00012615, -0.000125 , -0.00013154, -0.00012308, -0.00012 ],

[-0.00012423, -0.00011808, -0.00011577, -0.00012769, -0.00012923],

[-0.00012115, -0.00012308, -0.00011962, -0.00012538, -0.00012308],

[-0.00012808, -0.00013077, -0.00012808, -0.00012038, -0.00012885]])

diff_Y=np.array([[5.69230769e-05, 6.19230769e-05, 6.76923077e-05, 5.88461538e-05,

6.34615385e-05],

[5.73076923e-05, 6.92307692e-05, 6.19230769e-05, 6.61538462e-05,

6.34615385e-05],

[5.53846154e-05, 7.30769231e-05, 6.50000000e-05, 6.92307692e-05,

6.23076923e-05],

[6.57692308e-05, 5.57692308e-05, 6.50000000e-05, 6.38461538e-05,

6.76923077e-05],

[6.38461538e-05, 6.57692308e-05, 6.80769231e-05, 6.53846154e-05,

6.34615385e-05]])

#Computation of the matrix diff and the corresponding angles (arctan2)

for i in range(0,N):

for j in range(0,N):

diff

*[j] = math.sqrt(diff_X*

*[j]**2+diff_Y**[j]**2)*

arrow_diffarrow_diff

*[j] = np.arctan2(diff_Y**[j],diff_X**[j])*

j=j+1

i=i+1

#Plot of the map

fig, ax = plt.subplots()

im = ax.imshow(diff, interpolation='bicubic',

cmap=cm.inferno,

origin='upper',

vmax=diff.max(), vmin=diff.min())

# vmax=sum_max, vmin=sum_min)

X, Y = np.meshgrid(np.arange(0, N, 1), np.arange(0, N, 1))

U = np.cos(X*diff_X)

V = np.sin(Y*diff_Y)

Q = ax.quiver(X, Y, U, V, arrow_diff, units='width')

qk = ax.quiverkey(Q, X, Y, 0.2, labelpos='E',

coordinates='figure')

</code></pre>

<p>However, this is what I get:

<img src="https://i.sstatic.net/MBu2Bymp.png" alt="map" /></p>

<p>I can't figure out how to get the arrows pointing in the right direction for each coordinates and also how to adapt their size to be proportionnal to their argument <code>arctan2(diff_Yj=j+1

i=i+1

#Plot of the map

fig, ax = plt.subplots()

im = ax.imshow(diff, interpolation='bicubic',

cmap=cm.inferno,

origin='upper',

vmax=diff.max(), vmin=diff.min())

# vmax=sum_max, vmin=sum_min)

X, Y = np.meshgrid(np.arange(0, N, 1), np.arange(0, N, 1))

U = np.cos(X*diff_X)

V = np.sin(Y*diff_Y)

Q = ax.quiver(X, Y, U, V, arrow_diff, units='width')

qk = ax.quiverkey(Q, X, Y, 0.2, labelpos='E',

coordinates='figure')

</code></pre>

<p>However, this is what I get:

<img src="https://i.sstatic.net/MBu2Bymp.png" alt="map" /></p>

<p>I can't figure out how to get the arrows pointing in the right direction for each coordinates and also how to adapt their size to be proportionnal to their argument <code>arctan2(diff_Y

*[j],diff_X**[j])</code>.</p>*

<p>I would expect all the arrows pointing in one direction and with a size more or less constant. I tried changing the arguments of quiver and quiverkey but it doesn't work.</p><p>I would expect all the arrows pointing in one direction and with a size more or less constant. I tried changing the arguments of quiver and quiverkey but it doesn't work.</p>