题目
下 列选[1]项中可以隐藏坐标轴上轴脊的是()。A ax . spines [ 'top' ] . set _ color ( 'none' ) B ax . spines [ 'right' ] . set _ color ( 'none' ) C ax . spines [ 'bottom' ] . set _ color ( 'none' ) D ax . spines [ 'left' ] . set _ color ( 'none' )
下 列选[1]项中可以隐藏坐标轴上轴脊的是()。
A ax . spines [ 'top' ] . set _ color ( 'none' )
B ax . spines [ 'right' ] . set _ color ( 'none' )
C ax . spines [ 'bottom' ] . set _ color ( 'none' )
D ax . spines [ 'left' ] . set _ color ( 'none' )
题目解答
答案
ax.spines[top].set_color('none')可以隐藏上轴脊,
ax.spines[right].set_color('none')可以隐藏右轴脊,
ax.spines[bottom].set_color('none')可以隐藏下轴脊,
ax.spines[left].set_color('none')可以隐藏左轴脊。使用这些方法时,需要先获取对应的坐标轴对象ax,然后调用spines属性选择需要隐藏的轴脊,并通过set_color方法将轴脊颜色设置为'none'即可。
因此,本题答案为:A。
解析
本题考查Matplotlib中隐藏坐标轴轴脊的方法。关键在于理解:
- 轴脊(spines)是坐标轴的边框线条,分为上(top)、下(bottom)、左(left)、右(right)四个方向;
set_color('none')可将指定方向的轴脊设置为不可见;- 需正确对应选项中的方向键与实际隐藏的轴脊。
选项分析
- A.
ax.spines['top'].set_color('none')
隐藏上边的轴脊(坐标轴顶部边框)。 - B.
ax.spines['right'].set_color('none')
隐藏右边的轴脊(坐标轴右侧边框)。 - C.
ax.spines['bottom'].set_color('none')
隐藏下边的轴脊(坐标轴底部边框)。 - D.
ax.spines['left'].set_color('none')
隐藏左边的轴脊(坐标轴左侧边框)。
结论
题目要求选择可以隐藏坐标轴上轴脊的选项,因此正确答案为A(对应隐藏上轴脊)。