我有一个半对数图,我想去除xtick。我试着:

plt.gca().set_xticks([])
plt.xticks([])
ax.set_xticks([])

网格消失了(ok),但是小扁虱(在主要扁虱的地方)仍然存在。如何去除?


当前回答

# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top='off', bottom='off', left='off', right='off', labelleft='off', labelbottom='on')

其他回答

试着去掉标签(但不是蜱虫):

import matplotlib.pyplot as plt

plt.setp( ax.get_xticklabels(), visible=False)

例子

不完全是OP要求的,但是一个简单的方法禁用所有轴、线、勾和标签是简单地调用:

plt.axis('off')

有一个比John Vinyard给出的更好、更简单的解决方案。使用NullLocator:

import matplotlib.pyplot as plt

plt.plot(range(10))
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.show()
plt.savefig('plot')

以下是我在matplotlib邮件列表中找到的一个替代解决方案:

import matplotlib.pylab as plt

x = range(1000)
ax = plt.axes()
ax.semilogx(x, x)
ax.xaxis.set_ticks_position('none') 

# remove all the ticks (both axes), and tick labels on the Y axis
plt.tick_params(top='off', bottom='off', left='off', right='off', labelleft='off', labelbottom='on')