从matplotlib图中删除特定的滴答声 [英] Removing specific ticks from matplotlib plot

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

问题描述

我正在尝试从下面的图中删除原点刻度以阻止它们重叠,或者只是将它们彼此远离也很好,我试过这个:

I'm trying to remove the origin ticks from my plot below to stop them overlapping, alternatively just moving them away from each other would also be great I tried this:

xticks = ax.xaxis.get_major_ticks()
xticks[0].label1.set_visible(False)
yticks = ax.yaxis.get_major_ticks()
yticks[0].label1.set_visible(False)

但是,这删除了y轴的第一个和最后一个刻度,就像这样:

However this removed the first and last ticks from the y axis like so:

有人对如何执行此操作有想法吗?任何帮助将不胜感激.

Does anyone have an idea about how to do this? Any help would be greatly appreciated.

添加了更多示例代码

import matplotlib
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
plt.xlabel(xlab)
plt.ylabel(ylab)
ax.spines["right"].set_color('none')
ax.xaxis.set_ticks_position('top')
ax.yaxis.set_ticks_position('left')
ax.spines["bottom"].set_color('none')
ax.xaxis.set_label_position('top')
ax.spines['left'].set_color('black')
ax.spines['top'].set_color('black')
ax.tick_params(colors='black')
xticks = ax.xaxis.get_major_ticks()
xticks[0].label1.set_visible(False)
yticks = ax.yaxis.get_major_ticks()
yticks[-1].label1.set_visible(False)
for x, y in all:
    ax.plot(x, y, 'ro')

推荐答案

您就快到了.y轴的原点在底部.这意味着您要删除的刻度位于顶部,是最后一个,即 yticks[-1]:

You were almost there. The origin of the y axis is at the bottom. This means that the tick that you want to delete, being at the top, is the last one, that is yticks[-1]:

yticks[-1].set_visible(False)

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

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