2

I have a graph over

[1,2,3,4,5] 

with values that are quite small:

[0.000001,0.000002,...]

When I plot this, it shows the y axis ticks with the whole decimal. I would like something like

[1e-6,2e-6...]

to pop up instead. How can I do that?

alvarezcl
  • 579
  • 6
  • 22
  • matplotlib.ticker.ScalarFormatter has a scientific notation option: http://matplotlib.org/1.3.1/api/ticker_api.html?highlight=scalarformatter#matplotlib.ticker.ScalarFormatter You can define a ScalarFormatter and use it to provide string representations of floats, which you then set as ticklabels, if you don't like what it does on the axes. – cphlewis Mar 12 '15 at 02:32
  • Or, possibly better for your purposes, a FuncFormatter: http://stackoverflow.com/questions/20692503/what-is-the-correct-way-to-replace-matplotlib-tick-labels-with-computed-values?rq=1 – cphlewis Mar 12 '15 at 02:50

1 Answers1

2

This is probably what you are looking for:

import matplotlib.pyplot as plt ...

plt.ticklabel_format(style='sci', axis='y', scilimits=(0,0))

style sci for scientific notation, axis y to format y axis only, m,n to include all numbers for which scientific notation should be applied (0,0 for all)

ca_san
  • 183
  • 2
  • 11