Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。
matplotlib.axes.Axes.get_axisbelow()函数
matplotlib库的axiss模块中的Axes.get_axisbelow()函数用于获取轴刻度和网格线是高于还是低于大多数美术师。
用法: Axes.get_axisbelow(self)
参数:此方法不接受任何参数。
返回:此方法返回axislowed。通过该值,我们可以确定轴刻度线和网格线是位于大多数艺术家上方还是下方。
以下示例说明了matplotlib.axes中的matplotlib.axes.Axes.get_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')
x = ax.get_axisbelow()
ax.text(2, 15.7, "Result of get_axisbelow:" +str(x),
style ='italic', fontsize = 12, color ="green")
ax.set_title('matplotlib.axes.Axes.get_axisbelow() \
Example\n\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')
x = ax.get_axisbelow()
ax.text(2, 15.7, "Result of get_axisbelow:" +str(x),
style ='italic', fontsize = 12, color ="green")
ax.set_title('matplotlib.axes.Axes.get_axisbelow() \
Example\n\n', fontsize = 12, fontweight ='bold')
plt.show()
输出:
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.axes.Axes.get_axisbelow() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。