8000 [Bug]: axis set_xscale('log') interferes with set_xticks · Issue #27701 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
[Bug]: axis set_xscale('log') interferes with set_xticks #27701
Closed
@evanberkowitz

Description

@evanberkowitz

Bug summary

Setting ax.set_xscale('log') introduces unwanted minor ticks, even when set_xticks specifies minor=False.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

N = np.array([3, 5, 7, 9])
s = np.ones_like(N)

fig, ax = plt.subplots()
ax.plot(1/N, s)
ax.set_xlabel('1/N')
ax.set_xscale('log')
ax.set_xticks(1./N, labels=[f'1/{each_n}' for each_n in N], minor=False)
# ax.minorticks_off()

Actual outcome

A figure with a constant dataset, with xticks at 1/9, 1/7, 1/5, and 1/3, but ALSO at 3x10^-1, which is unwanted.
Screenshot 2024-01-25 at 13 12 11

What is that extra tick doing there?

Expected outcome

The figure that results from uncommenting the minorticks_off command in the example,

Screenshot 2024-01-25 at 13 13 12

Additional information

Happens with errorbar instead of plot. Haven't tested other ways to draw.

In the above example if you put the set_xscale after the set_xticks then the requested xticks are completely ignored.

If you comment out the log scale, the ticks are as expected (but of course the scale isn't what is desired).

Operating system

MacOS 14.2.1 (M2 from 2022)

Matplotlib Version

3.5.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.11.7

Jupyter version

4.0.5

Installation

conda

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0