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

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

网格消失(正常),但小刻度(在主刻度的位置)仍然存在.如何移除它们?

推荐答案

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

请注意,matplotlib.axes.Axes个对象也有ax.tick_params个.

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

enter image description here

Python相关问答推荐

有没有方法可以关闭Python多处理资源跟踪器进程?

使用unmanagedexports从Python调用的c#DLC

如何将不同长度的新列添加到现有的框架中

如何观察cv2.erode()的中间过程?

Polars Select 多个元素产品

在Transformer中使用LabelEncoding的ML模型管道

当值是一个integer时,在Python中使用JMESPath来验证字典中的值(例如:1)

在应用循环中间保存pandas DataFrame

根据不同列的值在收件箱中移动数据

Django mysql图标不适用于小 case

'discord.ext. commanders.cog没有属性监听器'

运行总计基于多列pandas的分组和总和

如何使用html从excel中提取条件格式规则列表?

如果值发生变化,则列上的极性累积和

为什么抓取的HTML与浏览器判断的元素不同?

Scrapy和Great Expectations(great_expectations)—不合作

转换为浮点,pandas字符串列,混合千和十进制分隔符

joblib:无法从父目录的另一个子文件夹加载转储模型

Python Pandas—时间序列—时间戳缺失时间精确在00:00

在Admin中显示从ManyToMany通过模型的筛选结果