matplotlib.axes.axes.vlines()
matplotlib.axes.axes.vlines()函数,matplotlib库的axis模块中的Axes.vlines()函数用于绘制从ymin到ymax的每个x的垂直线。
语法:
Axes.vlines(self, x, ymin, ymax, colors=’k’, linestyles=’solid’, label=”, *, data=None, **kwargs)
参数:该方法接受如下参数说明:
- x:该参数是绘制线条的x索引序列。
- ymin, ymax:这些参数包含一个数组.,它们表示每行的开始和结束。
- colors:可选参数。它是默认值为k的线条的颜色。
- linetsyle:可选参数。它被用来表示线型{‘ solid ‘, ‘虚线’,’ dashdot ‘, ‘ dot ‘}。
- label:该参数也是一个可选参数.它是情节的标签。
返回:
返回LineCollection。
下面的例子演示了matplotlib.axes中的matplotlib.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()
输出: