How to prevent numbers being changed to exponential form in Python matplotlib figure

The formatting of tick labels is controlled by a Formatter object, which assuming you haven't done anything fancy will be a ScalerFormatterby default. This formatter will use a constant shift if the fractional change of the values visible is very small. To avoid this, simply turn it off:

plt.plot(arange(0,100,10) + 1000, arange(0,100,10))
ax = plt.gca()
ax.get_xaxis().get_major_formatter().set_useOffset(False)
plt.draw()

If you want to avoid scientific notation in general,

ax.get_xaxis().get_major_formatter().set_scientific(False)

Can control this with globally via the axes.formatter.useoffset rcparam.


You can use a simpler command to turn it off:

plt.ticklabel_format(useOffset=False)

You can use something like:

from matplotlib.ticker import ScalarFormatter, FormatStrFormatter

ax.xaxis.set_major_formatter(FormatStrFormatter('%.0f'))

Use the following command: ax.ticklabel_format(useOffset=False, style='plain')

If you are using a subplot, you may experience the AttributeError: This method only works with the ScalarFormatter in which case you would add axis='y' like the below. You can change 'y' to the axis with the issues.

ax1.ticklabel_format(useOffset=False, style='plain', axis='y')

Source question and answer here. Note, the axis 'y' command use is hidden in the answer comments.