Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

To show intermediate ticks on a base-10 logarithmic axis, set that axis’s minor locator to LogLocator(base=10, subs=range(2, 10)). This requests positions at 2 through 9 times each integer power of 10—for example, 2, 3, …, 9 between 10 and 100. Tick positions and tick labels are separate: a locator chooses where marks go, while a formatter controls whether they receive labels.

Set a LogLocator for the axis you want to change

Set the axis to a logarithmic scale, then assign a LogLocator to its minor locator. For a y-axis, use ax.yaxis; for an x-axis, use ax.xaxis.

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)))

Replace x and y with your data. To apply the same pattern to the x-axis, use ax.xaxis.set_minor_locator(...). Matplotlib’s scale handling provides scale-specific locators and formatters; the code above explicitly configures the minor locator to request intermediate multiples. See the Matplotlib axis scales guide and the ticker API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose which multiples appear with subs

LogLocator places ticks according to subs[j] * base**i. With base 10, each value in subs is multiplied by powers of 10. The documented default, subs=(1.0,), places ticks at integer powers of the base; it does not request the familiar intermediate multiples.

  • Use an explicit sequence such as range(2, 10) when you want multiples 2 through 9 within each decade.
  • Use subs='auto' when you want the locator to choose intermediate positions based on the current view limits.
  • Use subs='all' when you want view-limit-dependent positions both between and at integer powers.
  • Use subs=None for the current documented API’s equivalent of 'auto'.

The number of generated ticks is also influenced by numticks. In the current API, its default is None; once the locator is attached to an axis, Matplotlib attempts to choose a suitable number. Without an attached axis, the documented fallback is 9. Consult the LogLocator API reference for the current signature and behavior.

Keep tick marks and labels distinct

A minor locator determines tick positions; a formatter determines their text labels. If the intermediate marks appear but have no labels, the locator may be working as intended. Matplotlib’s LogFormatter controls log tick labeling, including minor-label behavior through settings such as labelOnlyBase and minor_thresholds. Match the formatter’s base to the locator’s base.

If you want the minor marks but no minor labels, use a NullFormatter for the minor ticks. Avoid labeling every intermediate mark when the resulting text would crowd the plotted range. The formatter options are documented in the ticker API reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use defaults or specify the locator yourself

Axis.minorticks_on() turns on scale-dependent minor ticks; on a logarithmic axis, the default minor locator is a LogLocator. That is useful when the default pattern is sufficient. Set a specific LogLocator with subs when you need to control the multiples. See Axis.minorticks_on.

Make the locator work with zooming and multiple axes

Prefer a locator for interactive limits

Locators choose positions based on the current view limits, so locator-based ticks can adjust as you zoom or pan. Manually setting tick positions is more appropriate for a fixed final plot; manually chosen positions do not adapt to interaction. Matplotlib explains this distinction in its axis ticks guide.

Create a separate locator for each axis

Do not reuse one locator instance across multiple axes. The API documentation says locator instances should not be shared between axes; construct a new LogLocator for each axis that needs one.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check version-specific API details

The current stable references cited here are Matplotlib 3.11.2 for the ticker API and axes guides, and 3.11.1 for Axis.minorticks_on. Older Matplotlib documentation can show a different LogLocator signature—for example, the 3.6.1 reference includes a numdecs parameter. If you support an older installation, check that installed version’s documentation rather than assuming its API matches the current stable reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.