GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [Bug]: LogLocator with subs argument fragile. · Issue #24092 · matplotlib/matplotlib

[Bug]: LogLocator with subs argument fragile. #24092

New issue
Copy link
New issue
Copy link
Closed
#25405
Closed
[Bug]: LogLocator with subs argument fragile.#24092
#25405
Copy link
Labels
Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: ticks axis labels🌱 Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!
Milestone
v3.8.0

Description

@peterdsharpe
peterdsharpe
opened on Oct 4, 2022
Issue body actions

Bug summary

Logarithmic tick markers do not appear if the y-axis scales a sufficient range, with the subs keyword argument of ticker.LogLocator set to non-trivial values.

Code for reproduction

import matplotlib.pyplot as plt
import matplotlib.ticker
import numpy as np

ll = matplotlib.ticker.LogLocator(subs=(1, 2, 5))

### The following code produces a plot with y-axis ticks at the expected locations.

fig, ax = plt.subplots()
x = np.arange(8)
plt.semilogy(x, 10 ** x)
ax.yaxis.set_major_locator(ll)
ax.yaxis.set_minor_locator(ll)
plt.title("Good Plot")
plt.show()

### The following code produces a plot with no y-axis ticks, which is unexpected and undesired.

fig, ax = plt.subplots()
x = np.arange(9)  # The only change is this line
plt.semilogy(x, 10 ** x)
ax.yaxis.set_major_locator(ll)
ax.yaxis.set_minor_locator(ll)
plt.title("Bad Plot")
plt.show()

### The problem is isolated to here, which returns correct values in the first case, but np.array([]) in the second case:
print(ll.tick_values(1, 1e7))
print(ll.tick_values(1, 1e8))

Actual outcome

image

image

Expected outcome

I expect to see ticks in both cases, as appears in the "Good Plot".

Additional information

The problem is isolated to ticker.LogLocator.tick_values(). This returns correct values in the first case (e.g., np.array([1.e-01 2.e-01 5.e-01 1.e+00 2.e+00 5.e+00 1.e+01 2.e+01 5.e+01 1.e+02 2.e+02 5.e+02])), but np.array([]) in the second case.

Operating system

Windows

Matplotlib Version

3.5.2

Matplotlib Backend

module://backend_interagg

Python version

3.9.13

Jupyter version

No response

Installation

conda

Activity

Next
  1. jklymak
    changed the title [-][Bug]: [/-] [+][Bug]: LogLocator with subs argument fragile.[/+] on Oct 4, 2022
  2. jklymak
    added
    topic: ticks axis labels
    on Oct 4, 2022
  3. peterdsharpe commented on Oct 13, 2022

    @peterdsharpe
    peterdsharpe
    on Oct 13, 2022
    Author
    More actions

    Hi all, any thoughts on this? This is causing breaking behavior in a downstream application, and it'd be helpful to know whether Matplotlib maintainers think a fix will be quick, or if I should invest resources in working around this.

  4. jklymak commented on Oct 13, 2022

    @jklymak
    jklymak
    on Oct 13, 2022
    Member
    More actions

    I think we would accept a fix if one were forthcoming. I suspect the is in the range where we tick every two decades and that is clashing with subs.

  5. tacaswell
    added
    🌱 Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!
    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on Oct 13, 2022
  6. tacaswell commented on Oct 13, 2022

    @tacaswell
    tacaswell
    on Oct 13, 2022
    Member
    More actions

    If you pan the "bad" example up or down you can make the ticks show up. They seem to alternate in and out based on the limits (not just the range) if you zoom out further they never appear.

    There is clearly something very wrong in the logic of what sub does, but looking at the code I can not quickly understand it...

    I'm labeling this as "good first issue" as I think the bug is clear (we should never not have tick labels!) but "hard" because the logic in the tick_values method is a bit convoluted (for a bunch of reasons, some historical, some because we are using the same code for major and minor ticks, some because people have very strong views about what log tick "should" be that are very conditional on the values involved). Any changes will have to be very careful about unintended consequences and understanding why the code was the way it was (likely will require some git/github archaeology) and adding a bunch more tests.

    Reacted by Peter Sharpe and Pradyumn Rahar
  7. tacaswell
    added this to the v3.7.0 milestone on Oct 13, 2022
  8. tacaswell commented on Oct 13, 2022

    @tacaswell
    tacaswell
    on Oct 13, 2022
    Member
    More actions

    Also milestoning for 3.7 as we need to fix this, but I doubt (but we should check) that this is a regression in 3.6 and expect the fix to be somewhat high-risk so we should not backport it. If I am wrong about either of those, then we can re-milestone and backport.

    Reacted by Jody Klymak and Peter Sharpe
  9. Hannibal404 commented on Oct 20, 2022

    @Hannibal404
    Hannibal404
    on Oct 20, 2022
    More actions

    In ticker.py, as the difference between vmin and vmax increases, numdec increases and thus makes stride to be greater than 1 (in the else condition).

            stride = (max(math.ceil(numdec / (numticks - 1)), 1)
                  if mpl.rcParams['_internal.classic_mode'] else
                  (numdec + 1) // numticks + 1)
    

    In the case of stride > 1, ticklocs gets assigned a blank array which I believe to be the root of the problem.

        if hasattr(self, '_transform'):
            ticklocs = self._transform.inverted().transform(decades)
            if have_subs:
                if stride == 1:
                    ticklocs = np.ravel(np.outer(subs, ticklocs))
                else:
                    # No ticklocs if we have >1 decade between major ticks.
                    ticklocs = np.array([])
    

    The ticks appearing upon panning may be explained by numticks increasing due to staggering and thus stride being reduced to 1 again, as upon plotting the bad plot for x = np.arange(10) even panning does not make the ticks appear.

    Hope this helps. I would be glad to help fix this if you could guide me a little. Thanks

  10. Abitamim commented on Nov 1, 2022

    @Abitamim
    Abitamim
    on Nov 1, 2022
    Contributor
    More actions

    I would like to tackle this. Does matplotlib assign issues or is it open for anyone to attempt to fix and submit pull requests?

  11. ksunden commented on Nov 1, 2022

    @ksunden
    ksunden
    on Nov 1, 2022
    Member
    More actions

    @Abitamim we do not typically assign issues (sometimes core maintainers will self-assign as a reminder to themselves)

    For more info see https://matplotlib.org/stable/devel/contributing.html#issues-for-new-contributors

  12. ksunden
    modified the milestones: v3.7.0, v3.7.1 on Feb 14, 2023
  13. haval0
    added a commit that references this issue on Mar 1, 2023

    feat: add 2 tests based on good/bad plot from upstream issue

    da5796c
  14. 9 remaining items

  15. QuLogic
    added this to the v3.8.0 milestone on Mar 28, 2023
  16. Higgs32584
    added 2 commits that reference this issue on Apr 17, 2023

    feat: add 2 tests based on good/bad plot from upstream issue

    57dd2c1

    fix: revert simplification of stride calculation in LogLocator (matpl…

    31a17d8
  17. imgbot
    added 12 commits that reference this issue on Apr 19, 2026

    feat: add 2 tests based on good/bad plot from upstream issue

    7e3526d

    fix: revert simplification of stride calculation in LogLocator (#3)

    d420ede

    feat: add 2 tests based on good/bad plot from upstream issue

    9930e6c

    feat: add 2 tests based on good/bad plot from upstream issue

    8495b17

    feat: add 2 tests based on good/bad plot from upstream issue

    627b1b1

    feat: add 2 tests based on good/bad plot from upstream issue

    37633a0

    feat: add 2 tests based on good/bad plot from upstream issue

    5f357f9

    feat: add 2 tests based on good/bad plot from upstream issue

    e0b16a5

    feat: add 2 tests based on good/bad plot from upstream issue

    96f8ea8

    feat: add 2 tests based on good/bad plot from upstream issue

    2805439

    feat: add 2 tests based on good/bad plot from upstream issue

    02ccc22

    feat: add 2 tests based on good/bad plot from upstream issue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Hardhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issueshttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issuestopic: ticks axis labels🌱 Good first issueOpen a pull request against these issues if there are no active ones!Open a pull request against these issues if there are no active ones!

    Type

    No type

    Projects

    No projects

      Milestone

      • v3.8.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.