Python中的 Matplotlib.axes.Axes.set_axisbelow()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.set_axisbelow()函数
matplotlib 库的 axes 模块中的Axes.set_axisbelow()函数用于设置轴刻度和网格线是高于还是低于大多数艺术家。
Syntax: Axes.set_axisbelow(self, b)
Parameters: This method accept only one parameters.
Returns:This method does not returns anything.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.set_axisbelow()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size = 100) for std in range(1, 6)]
labels = ['x1', 'x2', 'x3', 'x4', 'x5']
fig, ax = plt.subplots()
bplot = ax.boxplot(all_data,
vert = True,
patch_artist = True,
labels = labels)
colors = ['lightpink', 'lightblue', 'lightgreen',
"lightgrey", "yellow"]
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor(color)
ax.yaxis.grid(True, color ="green", lw = 2)
ax.set_axisbelow(True)
ax.set_xlabel('Samples')
ax.set_ylabel('Observed values')
ax.set_title('matplotlib.axes.Axes.set_axisbelow() \
Example\n', fontsize = 12, fontweight ='bold')
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
# Random test data
np.random.seed(19680801)
all_data = [np.random.normal(0, std, size = 100) for std in range(1, 6)]
labels = ['x1', 'x2', 'x3', 'x4', 'x5']
fig, ax = plt.subplots()
bplot = ax.boxplot(all_data,
vert = True,
patch_artist = True,
labels = labels)
colors = ['lightpink', 'lightblue', 'lightgreen',
"lightgrey", "yellow"]
for patch, color in zip(bplot['boxes'], colors):
patch.set_facecolor(color)
ax.yaxis.grid(True, color ="green", lw = 2)
ax.set_axisbelow(False)
ax.set_xlabel('Samples')
ax.set_ylabel('Observed values')
ax.set_title('matplotlib.axes.Axes.set_axisbelow()\
Example\n', fontsize = 12, fontweight ='bold')
plt.show()
输出: