Skip to content

[Bug]: Setting ticks on log axis behaving unexpectedly  #25894

Closed
@Spl1x

Description

@Spl1x

Bug summary

The issue occurs when formatting an axis (y-axis in this example) with 'log' scale and manually setting the limits. The process of setting the major and minor tick locations then does not work as expected/ as usual.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

# This section (1) fails to set the major ticks to locations [14, 18, 22, 26]
ax.set_yscale('log')
ax.set_ylim(13.5,26.5)
ax.set_yticks([14, 18, 22, 26])

# Adding this line results in section (1) working as expected
ax.set_yticks([], minor=True)

# Trying to also set the location of minor ticks leads to the same failure as in section (1)
ax.set_yticks([16, 16.5, 20, 24], minor=True)

# Adding this line leads to the expected output again
ax.set_yticklabels([], minor=True)

plt.show()

Actual outcome

Despite calling set_yticks in section (1), the actual y-ticks remain at their default location. This first part of the issue can be resolved by setting the minor tick locations to an empty list.
When also trying to set the location of minor ticks, however, it seems that labels are automatically created for these minor ticks.

Expected outcome

Calling set_yticks() should set the location of both major and minor ticks independently without the need of changing both at the same time or having to set the minor ticklabels to an empty list.

Additional information

No response

Operating system

Debian GNU/Linux 11

Matplotlib Version

3.5.1

Matplotlib Backend

QtAgg

Python version

3.9.2

Jupyter version

No response

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions