删除matplotlib图中的xticks?

发布于 2021-01-29 15:00:10

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

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

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

关注者
0
被浏览
131
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    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()
    

    在此处输入图片说明



知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看