3

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:

                enter image description here

Instead, I would like to have a tick, say, every multiple of 100, or every multiple of 1000, while preserving a logarithmic scaling.

How can I do that in matplotlib?

Josh
  • 11,979
  • 17
  • 60
  • 96

1 Answers1

4

Just use matplotlib.ticker.LogLocator

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import LogLocator
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.

Phlya
  • 5,726
  • 4
  • 35
  • 54