How to show minor tick labels on log-scale with Matplotlib

You can use plt.tick_params(axis="y", which="minor") to set the minor ticks on and format them with the matplotlib.ticker FormatStrFormatter. For example,

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FormatStrFormatter
x = np.linspace(0,4,1000)
y = np.exp(x)
plt.plot(x, y)
ax = plt.gca()
plt.tick_params(axis="y", which="minor")

enter image description here

Leave a Comment