gpt4 book ai didi

python - 从 matplotlib `ax` 对象中提取刻度参数

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:54 25 4
gpt4 key购买 nike

我希望能够使用 ax.tick_params 识别刻度线是否设置为“关闭”。有没有办法检查 ax 对象以查看它们是否已关闭?

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.spines['top'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)


ax.tick_params(
axis='both',
which='both',

bottom='off',
top='off',
left='off',
right='off')

# This is essentially what I want to be able to do
assert ax.xticks == 'off'

最佳答案

要迭代每个轴的刻度,您可以使用此代码

print "Major ticks of y axis"                                              
for tick in ax.yaxis.get_major_ticks():
print tick.tick1On, tick.tick2On, tick.gridOn
print "Minor ticks of y axis"
for tick in ax.yaxis.get_minor_ticks():
print tick.tick1On, tick.tick2On, tick.gridOn

要在 x 轴的刻度上导航,例如,只需替换

ax.yaxis.get_major_ticks()

ax.xaxis.get_major_ticks()

关于 Tick 对象的可公开访问的属性,请阅读此处:http://matplotlib.org/api/axis_api.html#matplotlib.axis.Tick

关于python - 从 matplotlib `ax` 对象中提取刻度参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37447413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com