Python中的 Matplotlib.axes.Axes.quiver()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.quiver()函数
matplotlib 库的 axes 模块中的Axes.barbs()函数也用于绘制 2D 箭头字段。
Syntax: Axes.quiver(self, *args, data=None, **kw
Parameters: This method accept the following parameters that are described below:
- X, Y : These parameter are the x and y coordinates of the arrow locations.
- U, V: These parameter are the x and y components of the arrow vector.
- C : This parameter contains the numeric data that defines the arrow colors by colormapping via norm and cmap.
- pivot : This parameter is the part of the arrow that is anchored to the X, Y grid.
- units : This parameter is the arrow dimensions (except for length) are measured in multiples of this unit.
- angles : This parameter is the method for determining the angle of the arrows.
- scale : This parameter is the number of data units per arrow length unit.
- scale_units : This parameter is an optional parameter nad it contains these values ‘width’, ‘height’, ‘dots’, ‘inches’, ‘x’, ‘y’, ‘xy’ .
- width : This parameter is the shaft width in arrow units.
- headwidth : This parameter is the head width as multiple of shaft width.
- headlength : This parameter is the length width as multiple of shaft width.
- headwidth : This parameter is the head width as multiple of shaft width.
- headaxislength : This parameter is the head length at shaft intersection.
- minshaft : This parameter is the length below which arrow scales, in units of head length.
- minlength : This parameter is the minimum length as a multiple of shaft width.
- color : This parameter is the explicit color(s) for the arrows.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.quiver()函数:
示例 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)
fig, ax = plt.subplots()
q = ax.quiver(X, Y, U, V)
ax.set_title('matplotlib.axes.Axes.quiver()\
Example', fontsize = 14, fontweight ='bold')
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
fig, ax = plt.subplots()
ax.quiver(X, Y, U, V, C, units ='width')
ax.set_title('matplotlib.axes.Axes.quiver() \
Example', fontsize = 14, fontweight ='bold')
plt.show()
输出: