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

查看:49
本文介绍了删除 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?

推荐答案

plt.tick_params 方法对于这样的东西非常有用.此代码关闭主要和次要刻度并从 x 轴上删除标签.

The plt.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.

请注意,还有 ax.tick_params 用于 matplotlib.axes.Axes 对象.

Note that there is also ax.tick_params for matplotlib.axes.Axes objects.

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天全站免登陆