7

In a plot created by matplotlib.pyplot, how can I force the axis labels to be shown in exponential notation? This seems to be done automatically for values < 1e-6, but for, say, 5e-6 I get "0.000005". I'd prefer to have it shown as "5e-6" also for this range.

gandi2223
  • 275
  • 4
  • 8

1 Answers1

5

It seems like you should be able to set the power limits of the ScalarFormatter for the axes. (untested code)

# Set limits to x < 10^1 and x > 10^-1 
# (overlapping, thus all inclusive, hopefully)
gca().get_yaxis().get_major_formatter().set_powerlimits((0, 0))
voithos
  • 68,482
  • 12
  • 101
  • 116
  • 3
    You can do one better and just call `set_powerlimits` on `gca().get_major_formatter()` – tacaswell Jul 24 '13 at 23:24
  • 1
    @voithos: I had to use `gca().yaxis.get_major_formatter().set_powerlimits((-1,1))`. Is there an (elegant) way to apply the change to both axes in one go? @tcaswell: How do you do this? Calling `set_powerlimits` without arguments gived an error. – gandi2223 Jul 26 '13 at 02:22
  • 1
    @gandi2223 Sorry, dropped a layer. The elegant way is to just do it do both. If you want to change the default, set `axes.formatter.limits` in `matplotlib.rc` – tacaswell Jul 26 '13 at 03:59