Skip to content Skip to sidebar Skip to footer

Matplotlib: Format Axis Ticks Without Offset

I want to format my ticks to a certain number of significant figures, AND remove the automatic offset. For the latter I am using https://stackoverflow.com/a/6654046/1021819, and fo

Solution 1:

FormatStrFormatter doesn't use an offset, so by using your second format you automatically won't have an offset.

Compare the two subplots in this example

import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import numpy as np  

fig,(ax1,ax2)=plt.subplots(2)

ax1.plot(np.arange(10000,10010,1))

ax2.plot(np.arange(10000,10010,1))
ax2.yaxis.set_major_formatter(mtick.FormatStrFormatter('%.4e'))

plt.show()

enter image description here


Post a Comment for "Matplotlib: Format Axis Ticks Without Offset"