我想让箭头大小在2D quiver plot中完全相同。在数据文件中,它们具有不同的大小:
U = np.loadtxt("/home/brendan/software/tf2-model-g/arrays/quiver_array33/u.txt")
V = np.loadtxt("/home/brendan/software/tf2-model-g/arrays/quiver_array33/v.txt")主要代码如下:
nx, ny = 240, 426
x1 = range(nx)
y1 = range(ny)
#data
U = np.loadtxt("/home/brendan/software/tf2-model-g/arrays/quiver_array33/u.txt")
V = np.loadtxt("/home/brendan/software/tf2-model-g/arrays/quiver_array33/v.txt")
            
X1, Y1 = np.meshgrid(x1, y1)  # `plot_surface` expects `x` and `y` data to be 2D
            
fig, hf = plt.subplots(figsize=(10,10))
hf.set_title("Model G fluid velocity vector field - every 5th arrow, time = " + str(c1))
Q = hf.quiver(X1[::5, ::5], Y1[::5, ::5], U[::5, ::5], V[::5, ::5], units='width',
      pivot='mid', scale=0.1, headwidth=7)#pivot='mid', units='inches')
qk = hf.quiverkey(Q, 0.9, 0.9, 0.1, r'$\frac{distance}{time}$', labelpos='E',
      coordinates='figure')
hf.scatter(X1[::5, ::5], Y1[::5, ::5], color='r', s=5)
plt.savefig('/home/brendan/software/tf2-model-g/plots/2D_video40/2D_video_velocity_' + str(c1) + '.png')输出video-plot的截图如下所示:

@ Quiver matplotlib : arrow with the same sizes Derek Eden使用以下代码使随机u和v的箭头大小完全相同。我如何使其适用于非随机存储的数据?
x = np.arange(10)
y = np.arange(10)
xx, yy = np.meshgrid(x,y)
u = np.random.uniform(low=-1, high=1, size=(9,9))
v = np.random.uniform(low=-1, high=1, size=(9,9))
plt.quiver(xx, yy, u, v)发布于 2021-07-16 13:36:29
我通过使用U1、V1和归一化因子F对数据进行归一化处理,解决了这个问题
U = np.loadtxt("/home/brendan/software/tf2-model-g/arrays/quiver_array33/u.txt")
V = np.loadtxt("/home/brendan/software/tf2-model-g/arrays/quiver_array33/v.txt")
N = np.sqrt( U**2 + V**2 )  # normalize data
U1, V1 = U/N, V/N
#F = 0.001 # normalisation factor
F = 0.004
U1 *= F
V1 *= F
X1, Y1 = np.meshgrid(x1, y1)  # `plot_surface` expects `x` and `y` data to be 2D
fig, hf = plt.subplots(figsize=(10,10))
hf.set_title("Model G fluid velocity vector field - every 5th arrow, time = " + str(c1))
Q = hf.quiver(X1[::5, ::5], Y1[::5, ::5], U1[::5, ::5], V1[::5, ::5], units='width',
     pivot='mid', scale=0.1, headwidth=5)
qk = hf.quiverkey(Q, 0.9, 0.9, 0.1, r'$\frac{distance}{time}$', labelpos='E',
     coordinates='figure')
hf.scatter(X1[::5, ::5], Y1[::5, ::5], color='c', s=0)使用相同大小的矢量箭头生成的绘图图像:

https://stackoverflow.com/questions/68398823
复制相似问题