In Matplotlib, a log-log plot generates unwanted y-axis tick labels for the minor ticks. I tried this code, which specifies the (major) y-axis ticks to be [1,1.2,1.4,1.6] and expecting that any y-axis minor ticks will have no labels.
# imports
import numpy as np
from matplotlib import pyplot as plt
# data
x = np.linspace(0,4,31)
y1 = 1.7 - 0.3*x
y1min = y1-0.05
y1max = y1+0.05
# ticks
yticks = [1,1.2,1.4,1.6]
yticklabels = [str(yt) for yt in yticks]
# figure
plt.figure()
plt.plot(x,y1,color='r')
plt.ylim([0.9,1.6])
plt.xlabel('x')
plt.xscale('log')
plt.yscale('log')
plt.ylabel('y')
plt.yticks(yticks)
plt.gca().set_yticklabels(minor='off',labels=yticklabels)
plt.show()
which produces the following plot.
Surprisingly the minor y-axis ticks have the labels specified specified for the major ones (i.e. with incorrect values), while the major y-axis ticks have the correct values, but in scientific (exponential) notation instead of the desired normal notation.
How can I remove the minor tick labels on the y axis (hopefully without resorting to mticker
), while keeping the x-axis minor tick labels, and have the major y-axis tick labels follow the values I specified with yticklabels
?