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?

2
  • matplotlib.ticker.ScalarFormatter has a scientific notation option: matplotlib.org/1.3.1/api/… 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. Commented Mar 12, 2015 at 2:32
  • Or, possibly better for your purposes, a FuncFormatter: stackoverflow.com/questions/20692503/… Commented Mar 12, 2015 at 2:50

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.