Skip to content Skip to sidebar Skip to footer

How To Turn On Scientific Notation In Matplotilb Bar Chart?

I am trying to turn on scientific notation in this plot so that the numbers on the y-axis don't take up so much space. Currently my code is: import matplotlib.pyplot as plt import

Solution 1:

You can add these 3 lines before plt.show():

mf = mpl.ticker.ScalarFormatter(useMathText=True)
mf.set_powerlimits((-2,2))
plt.gca().yaxis.set_major_formatter(mf)

Check also this link for set_powerlimits() enter image description here


Solution 2:

You need to use the scilimits argument to set the limits over which the offset should be used.

ax.ticklabel_format(style='sci', axis='y', useOffset=True, scilimits=(0,0))

Post a Comment for "How To Turn On Scientific Notation In Matplotilb Bar Chart?"