By Igor Mikushkin


2012-08-07 23:06:00 8 Comments

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

2 comments

@zbyszek 2017-02-15 16:00:17

To disable relative shift everywhere, set the rc parameter:

import matplotlib
matplotlib.rc('axes.formatter', useoffset=False)

@khelwood 2017-02-15 16:26:26

Maybe you should add some explanation to your answer so it is not just code.

@bahrep 2017-02-15 17:58:51

While this code snippet may solve the question, including an explanation 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.

@zbyszek 2017-02-28 18:32:32

Updated to add an explanation.

@tacaswell 2012-08-08 05:18:19

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.

Related Questions

Sponsored Content

42 Answered Questions

[SOLVED] How to make a flat list out of list of lists?

44 Answered Questions

25 Answered Questions

[SOLVED] How can I safely create a nested directory?

13 Answered Questions

[SOLVED] How to remove a key from a Python dictionary?

39 Answered Questions

[SOLVED] How do I check whether a file exists without exceptions?

27 Answered Questions

[SOLVED] How do I check if a list is empty?

  • 2008-09-10 06:20:11
  • Ray
  • 2986713 View
  • 3234 Score
  • 27 Answer
  • Tags:   python list

20 Answered Questions

[SOLVED] Save plot to image file instead of displaying it using Matplotlib

  • 2012-03-08 17:38:10
  • Homunculus Reticulli
  • 1678191 View
  • 1188 Score
  • 20 Answer
  • Tags:   python matplotlib plot

17 Answered Questions

[SOLVED] How do you change the size of figures drawn with matplotlib?

21 Answered Questions

[SOLVED] How do I list all files of a directory?

  • 2010-07-08 19:31:22
  • duhhunjonn
  • 4544396 View
  • 3472 Score
  • 21 Answer
  • Tags:   python directory

10 Answered Questions

[SOLVED] Modify tick label text

  • 2012-06-28 12:20:00
  • repoman
  • 410280 View
  • 218 Score
  • 10 Answer
  • Tags:   python matplotlib

Sponsored Content