To add intermediate minor ticks to a base-10 logarithmic Matplotlib axis, set that axis’s minor locator to LogLocator(base=10, subs=range(2, 10)). This requests tick positions at 2 through 9 times each integer power of 10. Tick positions and their labels are configured separately.
Set the minor locator on the axis you want to change
Matplotlib applies scale-appropriate locators and formatters to logarithmic axes. The default LogLocator configuration uses subs=(1.0,), which places ticks at integer powers of the base; it does not request the familiar intermediate multiples between decades. Assign a locator explicitly when those marks are needed.
As an Amazon Associate I earn from qualifying purchases.
import matplotlib.pyplot as plt
from matplotlib.ticker import LogLocator
fig, ax = plt.subplots()
ax.set_yscale("log")
ax.plot(x, y)
ax.yaxis.set_minor_locator(LogLocator(base=10, subs=range(2, 10)))
For an x-axis, use ax.xaxis.set_minor_locator(...); for a y-axis, use ax.yaxis.set_minor_locator(...). The code shows the documented API pattern; supply your own x and y data. See the Matplotlib ticker API and its axis scales guide.
What subs controls
LogLocator places ticks according to subs[j] * base**i. With base 10, range(2, 10) requests the multiples 2, 3, …, 9 within each decade. The documented default, (1.0,), instead requests integer powers of the base.
#1 Best Overall
- Explicit sequence: Use values such as
range(2, 10)when you know which multiples you want. subs='auto': Let the locator choose ticks between integer powers according to the view limits.subs='all': Let the locator choose ticks between and at integer powers according to the view limits.subs=None: In the current documented API, this is equivalent to'auto'.
The number of ticks is also influenced by numticks. In the current API, its default is None; once the locator is attached to an axis, Matplotlib tries to choose an appropriate number. Without an attached axis, the documented fallback is 9. Consult the ticker API reference for the current signature and behavior.
Turn on defaults or choose specific multiples?
Axis.minorticks_on() enables scale-dependent minor ticks; on a log scale, the default minor locator is a LogLocator. Use it when the scale’s defaults suit the plot. Set a locator directly with set_minor_locator when you need to specify subs. See Axis.minorticks_on.
Rank #2
Keep tick positions and labels separate
The locator chooses where ticks appear. A LogFormatter determines which of those positions receive labels. Its base should match the locator’s base; its labelOnlyBase and minor_thresholds options affect minor tick labeling. If you want marks without labels, use a NullFormatter for the relevant minor ticks.
Do not assume every requested mark should carry a label: a dense set of labels can make a plot harder to read. Choose the positions with the locator, then decide how much labeling the figure can support. The formatter and locator API documentation describes these controls.
Make locators behave well when you zoom or pan
Locators select positions in relation to the axis view limits, so they can adapt as the view changes. Manually setting tick positions is more appropriate for a fixed final plot; those positions do not adapt during interaction. Prefer a locator for an axis users may zoom or pan. Matplotlib explains this distinction in its axis ticks guide.
Use a separate locator for each axis
Do not reuse one locator instance across multiple axes. The Matplotlib API documentation says a locator should be used with only one Axis or Axes; construct a fresh LogLocator for every axis that needs one.
Check version-specific API details
The current stable references consulted for this guidance are Matplotlib 3.11.2 for the ticker API and axis guides, and Matplotlib 3.11.1 for Axis.minorticks_on. Older documentation can show different LogLocator signatures, including a numdecs parameter in Matplotlib 3.6.1. If you support an older installation, verify the API in documentation for that version rather than assuming the current signature applies.
Recommended Free Tools
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




