【发布时间】:2021-07-15 18:06:19
【问题描述】:
我想让 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')
输出视频图的屏幕截图如下所示:
@Quiver matplotlib : arrow with the same sizesDerek 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)
【问题讨论】:
标签: python-3.x matplotlib