Python中的 matplotlib.axes.Axes.step()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.step()函数
matplotlib 库的 axes 模块中的Axes.errorbar()函数用于制作阶梯图。
Syntax:
Parameters: This method accept the following parameters that are described below:
- x, y: These parameter are the horizontal and vertical coordinates of the data points.
- fmt: This parameter is an optional parameter and it contains the string value.
- data: This parameter is also an optional parameter. And it is the object with labelled data.
- where: This parameter is also an optional parameter. And it is used to define where the steps should be placed. The values are {‘pre’, ‘post’, ‘mid’}. pre is the default value
Returns: This returns the following:
- lines:This returns the list of Line2D objects representing the plotted data.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.step()函数:
示例 1:
Axes.step(self, x, y, *args, where='pre', data=None, **kwargs)
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(16)
y = np.sin(x / 3)
fig, ax = plt.subplots()
ax.step(x, y + 2, color ='green')
ax.plot(x, y + 2, 'o--', color ='black', alpha = 0.3)
ax.set_title('matplotlib.axes.Axes.step Example1')
plt.show()
输出: