Matplotlib – logarithmic scale, but require non-logarithmic labels

If I understand correctly,

ax.set_yscale('log')

any of

ax.yaxis.set_major_formatter(matplotlib.ticker.ScalarFormatter())
ax.yaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter('%d'))
ax.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: str(int(round(x)))))

should work. ‘%d’ will have problems if the tick labels locations wind up being at places like 4.99, but you get the idea.

Note that you may need to do the same with the minor formatter, set_minor_formatter, depending on the limits of the axes.

Leave a Comment