一尘不染

删除matplotlib图中的xticks?

python

我有一个Semilogx图,我想删除xticks。我试过了:

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

网格消失(确定),但仍保留小刻度线(在主刻度线的位置)。如何删除它们?


阅读 192

收藏
2021-01-20

共1个答案

一尘不染

tick_params方法对于这样的事情非常有用。此代码关闭主要和次要刻度线,并从x轴删除标签。

from matplotlib import pyplot as plt
plt.plot(range(10))
plt.tick_params(
    axis='x',          # changes apply to the x-axis
    which='both',      # both major and minor ticks are affected
    bottom=False,      # ticks along the bottom edge are off
    top=False,         # ticks along the top edge are off
    labelbottom=False) # labels along the bottom edge are off
plt.show()
plt.savefig('plot')
plt.clf()

在此处输入图片说明

2021-01-20