Python中的 Matplotlib.axes.Axes.axhline()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.axhline()函数
matplotlib 库的 axes 模块中的Axes.axhline()函数用于在轴上添加一条水平线。
Syntax:
Parameters: This method accept the following parameters that are described below:
- y: This parameter is the y position in data coordinates of the horizontal line with default value of 0.
- xmin: This parameter should be between 0 and 1, 0 being the far left of the plot, 1 the far right of the plot.Its default value of 0.
- xmax: This parameter should be between 0 and 1, 0 being the far left of the plot, 1 the far right of the plot. Its default value of 1.
Returns: This returns the following:
- lines:This returns the list of Line2D objects representing the plotted data.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.axhline()函数:
示例 1:
Axes.axhline(self, y=0, xmin=0, xmax=1, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.collections as collections
t = np.arange(0.0, 2, 0.01)
s1 = np.sin(4 * np.pi * t)
s2 = 0.75 * np.sin(8 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s1, color ='black')
ax.axhline(0, color ='green', lw = 2)
ax.set_title('matplotlib.axes.Axes.axhline() Example')
plt.show()
输出: