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

查看:30
本文介绍了如何删除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 (doc).

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天全站免登陆