Python中的 Matplotlib.pyplot.quiverkey()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Pyplot是Matplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。在 Pyplot 中可以使用各种图,包括线图、等高线图、直方图、散点图、3D 图等。
matplotlib.pyplot.quiverkey()函数
matplotlib 库的 pyplot 模块中的quiverkey()函数用于向 quiver plot 添加键。
Syntax: matplotlib.pyplot.quiverkey(Q, X, Y, U, label, **kw)
Parameters: This method accept the following parameters that are described below:
- Q: This parameter is the Quiver instance returned by a call to quiver.
- X, Y : These parameter are the x and y coordinates of the location of the key.
- U: This parameter is the length of the key.
- label: This parameter is a string with the length and units of the key.
- angles : This parameter is the angle of the arrows.
- color : This parameter is the overrides face and edge colors from Q.
- labelpos : This parameter is used to position the label above, below, to the right, to the left of the arrow.
- labelsep: This parameter is the distance in inches between the arrow and the label.
- labelcolor: This defaults to default Text color.
- fontproperties: This parameter is the dictionary with keyword arguments accepted by the FontProperties initializer: family, style, variant, size, weight.
下面的示例说明了 matplotlib.axes 中的 matplotlib.pyplot.quiverkey()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
X = np.arange(-20, 20, 0.5)
Y = np.arange(-20, 20, 0.5)
U, V = np.meshgrid(X, Y)
q = plt.quiver(X, Y, U, V)
plt.quiverkey(q, X = 0.5, Y = 0.5,
U = 500, label ='Quiver key')
plt.title('matplotlib.pyplot.quiverkey() Example')
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
X, Y = np.meshgrid(np.arange(0, 2 * np.pi, .2), np.arange(0, 2 * np.pi, .2))
U = np.cos(X**2)
V = np.sin(Y**2)
C = U**2 + V**2
Q = plt.quiver(X, Y, U, V, C, units ='width')
plt.quiverkey(Q, 0.4, 0.9, 1,
r'val = $Cos(x ^ 2)^2 + Sin(x ^ 2)^2$',
labelpos ='E',
coordinates ='figure')
plt.title('matplotlib.pyplot.quiverkey() Example\n',
fontsize = 14, fontweight ='bold')
plt.show()
输出: