I tried many ways for small ticks to work correctly in logarithmic graphs. If you're okay with showing the checkmark log, you can use matplotlib.ticker.LogFormatterExponent . I remember trying matplotlib.ticker.LogFormatter , but I didnβt like it: if I remember well, it puts everything in base^exp (also 0,1, 0, 1). In both cases (like all the other matplotlib.ticker.LogFormatter* ) you need to set labelOnlyBase=False to get minor ticks.
In the end, I created a custom function and used matplotlib.ticker.FuncFormatter . My approach assumes that ticks have integer values ββand that you want to use a 10 log base.
from matplotlib import ticker import numpy as np def ticks_format(value, index): """ get the value and returns the value as: integer: [0,99] 1 digit float: [0.1, 0.99] n*10^m: otherwise To have all the number of the same size they are all returned as latex strings """ exp = np.floor(np.log10(value)) base = value/10**exp if exp == 0 or exp == 1: return '${0:d}$'.format(int(value)) if exp == -1: return '${0:.1f}$'.format(value) else: return '${0:d}\\times10^{{{1:d}}}$'.format(int(base), int(exp)) subs = [1.0, 2.0, 3.0, 6.0]
If you do not delete the main ticks and do not use subs = [2.0, 3.0, 6.0] , the font size of the main and minor ticks is different (this may be the reason using text.usetex:False in my matplotlibrc )
Francesco montesano
source share