2

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.

Zephyr
  • 11,891
  • 53
  • 45
  • 80
Ilya
  • 466
  • 2
  • 14
  • 1
    I'm confused. Setting the scales to "log" will automatically use the log locator. And in any case with and without your last line, I get ticks for every single decade. – Paul H Jun 09 '20 at 17:00
  • That's a good point about the automatic log locator. I'm not quite sure why I put it in, but I also have a minor locator. And when the major locator malfunctions as described, the minor ticks go away completely. – Ilya Jun 09 '20 at 18:54

1 Answers1

2

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

Zephyr
  • 11,891
  • 53
  • 45
  • 80