1

I want to use log_2 scale on the y axis for my plot and the ticks to be equidistant. However, what I get is. How can I achieve equidistant ticks with equal spacing?

Using the very same code for all three plots, only the first one is the way I intended it to be. I dont get it

axs[i].set_yscale("log", base=2)
axs[i].yaxis.set_major_locator(LogLocator(base=2))
axs[i].yaxis.set_minor_locator(LogLocator(base=2))
axs[i].plot(x, y)
plt.show()            

enter image description here

CD86
  • 979
  • 10
  • 27
  • Does this answer your question? [Controlling tick spacing in log-scale](https://stackoverflow.com/questions/27258156/controlling-tick-spacing-in-log-scale) – sophros Jun 11 '21 at 09:00
  • it does not. It doesnt change the plot at all – CD86 Jun 11 '21 at 09:09
  • The problem is not th number of ticks but their logarithmic spacing... – CD86 Jun 11 '21 at 09:17
  • How about providing [MInimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example)? – sophros Jun 11 '21 at 09:18
  • conceived a mwe and it works, so the problem is in my code apparently. I will keep checking. Thanks – CD86 Jun 11 '21 at 09:31

1 Answers1

0

The following code gives equidistant

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', base=2)
ax.yaxis.set_major_locator(LogLocator(base=2))
ax.yaxis.set_minor_locator(LogLocator(base=2))
ax.plot(x, y)
plt.show()

enter image description here

sophros
  • 14,672
  • 11
  • 46
  • 75