0

I am plotting values that are of order 10^-8 and I would like my inline plot in jupyter to output the yaxis ticks in that (scientific) notation. I tried :

plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.1E'))

as well as

plt.gca().yaxis.get_major_formatter().set_powerlimits((0, -10))

and

plt.ticklabel_format(style='sci')

but nothing seems to work. What am I doing wrong? I have the following example:

import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
import mpld3
mpld3.enable_notebook()
import matplotlib.ticker as mtick

a=5*10**-8
b=3*10**-8
x=np.arange(0,10,0.01)

y=a*x+b

plt.figure(figsize=(12,5))
plt.subplot(1,2,1)
plt.plot(x,y)
# plt.ticklabel_format(style='sci')
# plt.gca().yaxis.get_major_formatter().set_powerlimits((0, -10))
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.0e'))
plt.show()

Any pointers would be helpful as I don't find anything on this, besides ticks format of an axis in matplotlib, enter link description here or Change x axes scale in matplotlib NOTE: If I comment out the lines with import mpld3 and mpld3.enable_notebook() then it works but cannot interact with the plot... Is there some special treatment of matplotlib when plotting inline in jupyter? Thanks!

HCRuiz
  • 65
  • 10
  • 1
    Could you share a full [MCVE], and an image showing the current output to explain where it is wrong? – tmdavison Nov 10 '17 at 14:12
  • Thanks for your comment tom. I edited the question to include an example. Sorry for the "radio silence" until now. – HCRuiz Nov 21 '17 at 13:58

1 Answers1

0

You can use set_yticklabels to have a similar looking output.

ax = plt.gca()
ax.set_yticklabels(['10^-8','2*10^-8','3*10^-8','4*10^-8'])
Meher Béjaoui
  • 352
  • 2
  • 10