使用 matplotlib 添加额外的轴刻度 [英] adding extra axis ticks using matplotlib

查看:37
本文介绍了使用 matplotlib 添加额外的轴刻度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的情节代码

I have a simple plot code as

plt.plot(x,y)
plt.show()

我想在x轴上添加除当前刻度之外的一些额外刻度,比如说

I want to add some extra ticks on the x-axis in addition to the current ones, let's say at

extraticks=[2.1, 3, 7.6]

如您所见,我没有刻度线模式,所以我不想增加整个轴的刻度线频率;只需保留原始内容并添加其他内容...

As you see I do not have a pattern for ticks so I do not want to increase the tick frequency for the whole axis; just keep the original ones and add those extras...

有可能吗?

致谢

推荐答案

是的,您可以尝试以下操作:

Yes, you can try something like:

plt.xticks(list(plt.xticks()[0]) + extraticks)

要使用的函数是 xticks().当不带参数调用时,它返回当前的刻度.使用参数调用它,您可以设置刻度位置以及标签(可选).

The function to use is xticks(). When called without arguments, it returns the current ticks. Calling it with arguments, you can set the tick positions and, optionally, labels.

这篇关于使用 matplotlib 添加额外的轴刻度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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