Skip to content

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

@peterdsharpe

Description

@peterdsharpe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy