27

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

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

1000.0  1000.5  1001.0  1001.5  1002.0
Hooked
  • 84,485
  • 43
  • 192
  • 261
Igor Mikushkin
  • 1,250
  • 16
  • 25

2 Answers2

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

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

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

tacaswell
  • 84,579
  • 22
  • 210
  • 199
3

To disable relative shift everywhere, set the rc parameter:

import matplotlib
matplotlib.rc('axes.formatter', useoffset=False)
zbyszek
  • 5,105
  • 1
  • 27
  • 22
  • 1
    Maybe you should add some explanation to your answer so it is not just code. – khelwood Feb 15 '17 at 16:26
  • While this code snippet may solve the question, [including an explanation](http://meta.stackexchange.com/questions/114762/explaining-entirely-code-based-answers) really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion. – bahrep Feb 15 '17 at 17:58
  • Updated to add an explanation. – zbyszek Feb 28 '17 at 18:32