Skip to content

[ENH]: minor ticks for symlog norms (with integer base) #25994

Open

Description

@neutrinoceros

Problem

As of matplotlib 3.7.1, matplotlib.colors.SymLogNorm doesn't produce any minor tick (that doesn't overlap with major ticks). I understand that default minor tick locations are absolutely not obvious in the general case and, where the log base can be any real number, however, I think there's a case to be had regarding the special (and very useful) case of integer log bases (10 and 2 are probably among the most useful bases all domains considered), in which the interval between two major ticks n and n+1 can be divided by the interval between ticks n-1 and n (where n+1 is farthest from 0).

If fact matplotlib.colors.LogNorm uses log10 and produces minorticks by default. The difference in behaviour is perhaps best illustrated in a case where everything else is identical

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import SymLogNorm, LogNorm

prng = np.random.RandomState(0)
data = 50 * (prng.random_sample((10, 10)))

fig, axs = plt.subplots(ncols=2, figsize=(10,3))

for ax, norm in zip(axs, [LogNorm(), SymLogNorm(base=10, linthresh=1)]):
    im = ax.imshow(data, cmap="viridis_r", norm=norm)
    cb = fig.colorbar(im, ax=ax)
    cb.minorticks_on()

sfile = "/tmp/test.png"
print(f"saving to {sfile}")
fig.savefig(sfile)

test

Here's my attempt to reproduce what's happening internally (within cb.minorticks_on()) with a more minimal example

import matplotlib.ticker as mticker

log_t = mticker.LogLocator(base=10, subs=None)
symlog_t = mticker.SymmetricalLogLocator(linthresh=1, base=10, subs=None)

print(log_t.tick_values(vmin=1, vmax=100))
print(symlog_t.tick_values(vmin=1, vmax=100))

outputs

[2.e-01 3.e-01 4.e-01 5.e-01 6.e-01 7.e-01 8.e-01 9.e-01 2.e+00 3.e+00
 4.e+00 5.e+00 6.e+00 7.e+00 8.e+00 9.e+00 2.e+01 3.e+01 4.e+01 5.e+01
 6.e+01 7.e+01 8.e+01 9.e+01 2.e+02 3.e+02 4.e+02 5.e+02 6.e+02 7.e+02
 8.e+02 9.e+02 2.e+03 3.e+03 4.e+03 5.e+03 6.e+03 7.e+03 8.e+03 9.e+03]
[  1.  10. 100.]

I think that it is reasonable to expect SymmetricalLogLocator and LogLocator to produce identica ticks in this case (for values above linthresh), and this behaviour could be generalised to any integer base.

Proposed solution

At the moment I don't have a working patch for this. What I do not understand is how major ticks are sorted out from minor ticks in the case LogLocator. With a better understanding of the internals I'm willing to bet that the behaviour I expect should be easy to implement, and I'm more than willing to contribute it, but I may need some guidance.

Activity

  1. neutrinoceros commented on May 29, 2023

    @neutrinoceros
    ContributorAuthor

    I dug a little more in this and here are a couple additional notes:

    • an axis uses 2 tick locators, for major and minor ticks respectively, but from the perspective of a locator, there is no direct way to know if it's major or minor. LogLocator.tick_values() in fact uses a heuristic to try and distinguish those two cases:
      # Does subs include anything other than 1? Essentially a hack to know
      # whether we're a major or a minor locator.
      have_subs = len(subs) > 1 or (len(subs) == 1 and subs[0] != 1.0)
    • while LogLocator's base can be !=10, base 10 is still very much ingrained in LogNorm (LogNorm.__init__ doesn't have a base argument), so there's probably room for improvement regarding API consistency (SymLogNorm has a base argument). Maybe it should take priority over minor ticks inconsistency.
  2. github-actions commented on Jul 20, 2026

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  3. neutrinoceros commented on Jul 20, 2026

    @neutrinoceros
    ContributorAuthor

    as far as I know this is still relevant

  4. timhoffm commented on Jul 20, 2026

    @timhoffm
    Member

    #27310 is on a good way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions