删除matplotlib图中的xticks? [英] Remove xticks in a matplotlib plot?

查看:120
本文介绍了删除matplotlib图中的xticks?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a semilogx plot and I would like to remove the xticks. I tried:

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

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

The grid disappears (ok), but small ticks (at the place of the main ticks) remain. How to remove them?

推荐答案

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

The tick_params method is very useful for stuff like this. This code turns off major and minor ticks and removes the labels from the x-axis.

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

这篇关于删除matplotlib图中的xticks?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆