Matplotlib 简明教程
Matplotlib - Quiver Plot
颤动图显示了速度矢量,即在点 (x,y) 具有分量 (u,v) 的箭头。
A quiver plot displays the velocity vectors as arrows with components (u,v) at the points (x,y).
quiver(x,y,u,v)
以上命令将矢量绘制成箭头,箭头位于 x 和 y 中每个相应元素对指定坐标处。
The above command plots vectors as arrows at the coordinates specified in each corresponding pair of elements in x and y.
Parameters
下表列出了颤动图的不同参数 −
The following table lists down the different parameters for the Quiver plot −
x |
1D or 2D array, sequence. The x coordinates of the arrow locations |
y |
1D or 2D array, sequence. The y coordinates of the arrow locations |
u |
1D or 2D array, sequence. The x components of the arrow vectors |
v |
1D or 2D array, sequence. The y components of the arrow vectors |
c |
1D or 2D array, sequence. The arrow colors |
以下代码绘制了一个简单的羽化图 −
The following code draws a simple quiver plot −
import matplotlib.pyplot as plt
import numpy as np
x,y = np.meshgrid(np.arange(-2, 2, .2), np.arange(-2, 2, .25))
z = x*np.exp(-x**2 - y**2)
v, u = np.gradient(z, .2, .2)
fig, ax = plt.subplots()
q = ax.quiver(x,y,u,v)
plt.show()