Search code examples
pythonmatplotlibplotscientific-notation

Python Plot yyplot scientific notation not working


I have the code running properly, producing a plot but I don't see the scientific notation. Don't know why?

code:

fig,ax1 =  plt.subplots()
ax1.plot(x,y,'-',color=yclr)
ax1.ticklabel_format(style='sci', axis='y')
ax2 = ax1.twinx()
ax2.plot(x,yy,'-',color=yyclr)
ax2.ticklabel_format(style='sci', axis='y')
plt.show()  

Plot: enter image description here

Update: Based on the accepted answer, I just included scilimits=(0,0) and it worked. But scientific limit font size is higher than rest, which were set to 12.

enter image description here


Solution

  • Passing scilimits=(0, 0) to ticklabel_format should trigger it.

    fig,ax1 =  plt.subplots()
    ax1.plot(x,y,'-',color=yclr)
    ax1.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
    ax2 = ax1.twinx()
    ax2.plot(x,yy,'-',color=yyclr)
    ax2.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
    plt.show()