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 do I merge two dictionaries in a single expression?

21 Answered Questions

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

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

34 Answered Questions

[SOLVED] How do I sort a dictionary by value?

25 Answered Questions

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

38 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 Vega
  • 2612725 View
  • 3234 Score
  • 27 Answer
  • Tags:   python list

16 Answered Questions

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

28 Answered Questions

[SOLVED] How can I remove a trailing newline?

  • 2008-11-08 18:25:24
  • RidingThisToTheTop
  • 1707436 View
  • 1613 Score
  • 28 Answer
  • Tags:   python newline trailing

18 Answered Questions

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

  • 2012-03-08 17:38:10
  • Homunculus Reticulli
  • 1479234 View
  • 1084 Score
  • 18 Answer
  • Tags:   python matplotlib plot

9 Answered Questions

[SOLVED] Modify tick label text

  • 2012-06-28 12:20:00
  • repoman
  • 350583 View
  • 185 Score
  • 9 Answer
  • Tags:   python matplotlib

Sponsored Content