Python中的 matplotlib.axes.Axes.vlines()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.vlines()函数
matplotlib 库的 axes 模块中的Axes.vlines()函数用于在每个 x 处绘制从 ymin 到 ymax 的垂直线。
Syntax: Axes.vlines(self, x, ymin, ymax, colors=’k’, linestyles=’solid’, label=”, *, data=None, **kwargs)
Parameters: This method accept the following parameters that are described below:
- x: This parameter is the sequence of x-indexes where to plot the lines.
- ymin, ymax: These parameter contains an array.And they represents the beginning and end of each line.
- colors: This parameter is an optional parameter. And it is the color of the lines with default value k.
- linetsyle: This parameter is also an optional parameter. And it is used to represent the linestyle{‘solid’, ‘dashed’, ‘dashdot’, ‘dotted’}.
- label: This parameter is also an optional parameter.It is the label of the plot.
Returns: This returns the LineCollection.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.vlines()函数:
示例 #1:
# Implementation of matplotlib function
import numpy as np
from matplotlib import patches
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.vlines([1, 2, 3, 4], 0, 1,
color ="green",
transform = ax.get_xaxis_transform())
ax.set_title('matplotlib.axes.Axes.vlines Example')
plt.show()
输出:
示例 #2:
# Implementation of matplotlib function
import numpy as np
from matplotlib import patches
import matplotlib.pyplot as plt
t = np.arange(0.0, 5.0, 0.1)
s = np.exp(-t) + np.cos(3 * np.pi * t) + np.sin(np.pi * t)
nse = np.random.normal(0.0, 0.8, t.shape) * s
fig, ax = plt.subplots()
ax.vlines(t, [0], s)
ax.vlines([1, 2], 0, 1, color ="lightgreen",
transform = ax.get_xaxis_transform())
ax.set_xlabel('time (s)')
ax.set_title('matplotlib.axes.Axes.vlines Example')
plt.show()
输出: