当我使用ax.set_yscale('log')时如何摆脱原始的yticks/yticklabels [英] How to get rid of the original yticks/yticklabels when I use ax.set_yscale('log')

查看:28
本文介绍了当我使用ax.set_yscale('log')时如何摆脱原始的yticks/yticklabels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用符号图绘制一些值.我需要使用

I am plotting some values in a semilogy plot. I need to use the

ax.set_yscale('log')

而不是

ax.semilogy(...

因为我有一些带有负值的数组(所以我可以将比例设置为 symlog).

because i have some arrays with negative values (so I can set the scale to symlog).

我的代码

ax = plt.subplot(132)
ax.set_yscale('log')
ax.plot(np.arange(0,4),array,'-o')
ax.errorbar(np.arange(0,4),array,yerr=[yerr_neg,yerr_pos])
ax.set_yticks(np.exp(np.arange(-0.4,0.5,0.1)))
ax.set_yticklabels(np.arange(-0.4,0.5,0.1))

但是自动放置的刻度和标签仍然存在:

however the automatically placed ticks and labels are still there:

如何正确删除原始刻度/标签?通过消除绘图线(即删除ax.plot线或ax.errorbar线),我仍然遇到相同的错误

how do I properly get rid of the original ticks/labels? I get still the same error by eliminating either plot line (meaning deleting the ax.plot line or the ax.errorbar line)

推荐答案

显示的标签是次要刻度标签.您可以将次要刻度设置为空列表以摆脱它们.

The labels shown are minor ticklabels. You may set the minor ticks to an empty list to get rid of them.

ax.set_yticks([], minor=True)

或者只是设置小刻度,

ax.minorticks_off()

这篇关于当我使用ax.set_yscale('log')时如何摆脱原始的yticks/yticklabels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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