Python中的 Matplotlib.axes.Axes.streamplot()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.streamplot()函数
matplotlib 库的 axes 模块中的Axes.streamplot()函数也用于绘制矢量流的流线。
Syntax: Axes.streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, cmap=None, norm=None, arrowsize=1, arrowstyle=’-|>’, minlength=0.1, transform=None, zorder=None, start_points=None, maxlength=4.0, integration_direction=’both’, *, data=None)
Parameters: This method accept the following parameters that are described below:
- X, Y : These parameter are the x and y coordinates of the evenly spaced grid.
- U, V: This parameter is the The number of rows and columns must match the length of y and x.
- density : This parameter is used to controls the closeness of streamlines.
- linewidth : This parameter is the width of the stream lines.
- color : This parameter is the streamline color.
- cmap : This parameter is used to plot streamlines and arrows.
- norm : This parameter is used to normalize object used to scale luminance data to 0, 1.
- arrowsize : This parameter is the scaling factor for the arrow size.
- minlength : This parameter is the minimum length of streamline in axes coordinates..
- maxlength : This parameter is the maximum length of streamline in axes coordinates.
- zorder : This parameter is the zorder of the stream lines and arrows.
Returns:This method returns the following:
- stream_container :This returns the StreamplotSet
Container object with attributes
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.streamplot()函数:
示例 1:
# 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)
fig, ax = plt.subplots()
ax.streamplot(X, Y, U, V, density =[0.5, 1])
ax.set_title('matplotlib.axes.Axes.streamplot()\
Example\n', 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)
fig, (ax, ax1)= plt.subplots(nrows = 2, ncols = 1)
ax.streamplot(X, Y, U, V, density =[0.5, 1],
color = V * U, linewidth = 2,
cmap ='autumn')
val = np.array([[2, 1, 0, 1, 2, 1],
[2, 1, 0, 1, 2, 2]])
ax1.streamplot(X, Y, U, V, color = V * U, linewidth = 2,
cmap ='autumn',
start_points = val.T)
ax.set_title('matplotlib.axes.Axes.streamplot() \
Example\n', fontsize = 14, fontweight ='bold')
plt.show()
输出: