如何删除Matplotlib轴上的相对位移 [英] How to remove relative shift in matplotlib axis

查看:95
本文介绍了如何删除Matplotlib轴上的相对位移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试对数字足够大的范围进行绘图时,我得到了所有刻度线都具有相对偏移的轴.例如:

When I try to do a plot against a range with big enough numbers I get an axis with relative shift for all the ticks. For example:

plot([1000, 1001, 1002], [1, 2, 3])

我在横坐标轴上得到了这些刻度:

I get these ticks on axis of abscissas:

0.0     0.5     1.0     1.5     2.0
                               +1e3

问题是如何删除+1e3并获得公正待遇:

The question is how to remove +1e3 and get just:

1000.0  1000.5  1001.0  1001.5  1002.0

推荐答案

plot([1000, 1001, 1002], [1, 2, 3])
gca().get_xaxis().get_major_formatter().set_useOffset(False)
draw()

这将获取当前的axes,获取x轴axis对象,然后获取主要的格式化程序对象,并将useOffset设置为false(

This grabs the current axes, gets the x-axis axis object and then the major formatter object and sets useOffset to false (doc).

在matplotlib的较新版本(1.4+)中,可以通过axes.formatter.useoffset rcparam更改默认行为.

In newer versions (1.4+) of matplotlib the default behavior can be changed via the axes.formatter.useoffset rcparam.

这篇关于如何删除Matplotlib轴上的相对位移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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