Skip to content Skip to sidebar Skip to footer

Controlling Tick Spacing In Log-scale

When I apply: ax.set_yscale('log') to an axes in matplotlib, it creates a tick for every multiple of 10. Sometimes, this can bee to much, e.g. see screenshot below:         �

Solution 1:

Just use matplotlib.ticker.LogLocator

import numpy as np
import matplotlib.pyplotas plt
from matplotlib.tickerimportLogLocator
x = np.linspace(0, 10, 10)
y = 2**x
f = plt.figure()
ax = f.add_subplot(111)
plt.yscale('log')
ax.yaxis.set_major_locator(LogLocator(base=100))
ax.plot(x, y)
plt.show()

enter image description here And do the same with minor locator if you wish, or adjust it any other way you like.

Post a Comment for "Controlling Tick Spacing In Log-scale"