Python的Matplotlib.pyplot.quiver是如何工作的?
要使用 quiver ,我们可以遵循以下步骤:
- 设置图形大小并调整子图之间和周围的填充。
-
使用numpy数组创建向量坐标。
-
获取 x,y,u 和 v 数据点。
-
创建新图或使用 figure() 方法激活现有图。
-
使用 gca() 方法获取当前轴。
-
设置轴的 x 和 y 限制。
-
使用 draw() 方法重新绘制当前图。
-
使用 show() 方法显示图。
示例
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
soa = np.array([[0, 0, 3, 2], [0, 0, 4, 5], [0, 0, 9, 9]])
X, Y, U, V = zip(*soa)
plt.figure()
ax = plt.gca()
ax.quiver(X, Y, U, V, angles='xy', scale_units='xy', scale=1, color=['red', 'green', 'yellow'])
ax.set_xlim([-1, 10])
ax.set_ylim([-1, 10])
plt.draw()
plt.show()