October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

Matplotlib Log-Scale Minor Ticks: Choose Multiples with LogLocator

Use Matplotlib’s LogLocator with an explicit subs sequence to add minor ticks between decades, or choose view-dependent placement with auto or all.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

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

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.

  • 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.

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.

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

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.

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

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.