Python中的 Matplotlib.axes.Axes.stem()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.stem()函数
matplotlib 库的 axes 模块中的Axes.stem()函数用于创建茎图。
Syntax: Axes.stem(self, *args, linefmt=None, markerfmt=None, basefmt=None, bottom=0, label=None, use_line_collection=False, data=None)
Parameters: This method accept the following parameters that are described below:
- x: This parameter is the sequence of x coordinates of the stems.
- y: This parameter is the sequence of y coordinates of the stem heads.
- linefmt: This parameter is the string defining the properties of the vertical lines.
- markerfmt: This parameter is the string defining the properties of the markers at the stem heads.
- basefmt: This parameter is the string defining the properties of the baseline.
- bottom: This parameter is the y-position of the baseline.
- label: This parameter is the label to use for the stems in legends.
Returns: This returns the following:
- StemContainer: This returns the container which may be treated like a tuple (markerline, stemlines, baseline).
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.broken_barh()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.stem([0.3, 1.5, 2.7],
[1, 3.6, 2.7],
label ="stem test")
ax.legend()
ax.set_title('matplotlib.axes.Axes.stem Example')
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))
fig, ax = plt.subplots()
ax.stem(x, y, linefmt ='grey',
markerfmt ='D',
bottom = 1.1,
use_line_collection = True)
ax.set_title('matplotlib.axes.Axes.stem Example')
plt.show()