Why does LogLocator give me only one tick per 2 decades?

Viewed 450

First, the code. I'm using Jupyter Notebook 6.0.3 (which may or may not matter).

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

Nmax = 6
x = np.logspace(-1, Nmax)
y = 1/x + x

W = 8
plt.figure(figsize=(W, 4))
plt.plot(x, y)
ax = plt.gca()
ax.set_xscale('log')
ax.set_yscale('log')
ax.xaxis.set_major_locator(mpl.ticker.LogLocator())

This works fine. I get ticks on the X axis at each power of 10.

But if I set Nmax=7, I only get ticks at even powers of 10 (i.e., 0, 100, etc.) Increasing W (such as W=20) doesn't matter -- I get a larger figure with the same ticks.

I tried reading the docs for LogLocator. They don't actually explain all of the input args.

1 Answers

You could set again the xtick, as in this code:

import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

Nmax = 7
x = np.logspace(-1, Nmax)
y = 1/x + x

W = 8
fig, ax = plt.subplots(1, 1, figsize = (W, 4))
ax.loglog(x, y)

locmaj = mpl.ticker.LogLocator(numticks=12)
ax.xaxis.set_major_locator(locmaj)

plt.show()

enter image description here

Related