我有一个半对数图,我想去除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')

其他回答

这个问题的一个简单解决方案是将xtick的颜色设置为白色或任何背景色。这将隐藏xticks的文本,但不隐藏xticks本身。

import matplotlib.pyplot as plt
plt.plot()
plt.xticks(color='white')
plt.show()

结果

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

import matplotlib.pyplot as plt

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

例子

# 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')

有一个比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')

那些正在寻找一个短命令来关闭所有刻度和标签的人应该没问题

plt.tick_params(top=False, bottom=False, left=False, right=False,
                labelleft=False, labelbottom=False)

这允许类型bool为各自的参数,因为版本matplotlib>=2.1.1

对于自定义标记设置,文档是有帮助的:

https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.tick_params.html