我使用 imshow 将矩阵“diff”(输入矩阵 diff_X 和 diff_Y 的二次和)绘制为彩色图,我想显示箭头,显示每个坐标的相应角度 arctan2(diff_Y/diff_X)。这是我到目前为止的计划:
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')
但是,这就是我得到的:
我不知道如何让箭头指向每个坐标的正确方向,以及如何调整它们的大小以使其与参数成比例
arctan2(diff_Y[i][j],diff_X[i][j])
。
我希望所有箭头都指向一个方向,并且大小或多或少恒定。我尝试更改 quiver 和 quiverkey 的参数,但不起作用。