Python中的 Matplotlib.axes.Axes.axvspan()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.axvspan()函数
matplotlib 库的 axes 模块中的Axes.axvspan()函数用于在轴上添加垂直跨度(矩形)。
Syntax:
Parameters: This method accept the following parameters that are described below:
- xmin: This parameter indicates the first X-axis coordinate of the vertical span rectangle in data units.
- xmax: This parameter indicates the second X-axis coordinate of the vertical span rectangle in data units.
- ymin: This parameter indicates the first Y-axis coordinate of the vertical span rectangle in relative Y-axis units .
- ymax: This parameter indicates the second Y-axis coordinate of the vertical span rectangle in relative Y-axis units.
Returns: This returns the vertical span (rectangle) from (xmin, ymin) to (xmax, ymax).
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.axhspan()函数:
示例 1:
Axes.axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
ax.axvspan(1.5, 2.5, facecolor ='g', alpha = 0.7)
ax.set_title('matplotlib.axes.Axes.axvspan() Example')
plt.show()
输出: