Skip to content

[Bug]: Cannot set y_ticks for small intervals in logscale #23163

Closed
@VictorSeven

Description

@VictorSeven

Bug summary

I am plotting a graph in logscale and I want to set manually the y_ticks. However, in the graph I was using, ax.set_yticks was not doing anything. I found out that when ax.set_ylim is set to a large enough interval, I can have my custom yticks, but when the interval is small, ticks get "locked" and there is no way to change them to my liking.

I did check that the issue only happens when plotting in logscale, hence I do believe that the problem is related to this or a similar issue: #8768

I do provide a minimal working example below.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
plt.figure()  

#Generate some dummy power-law data that looks linear in log-log
x = np.linspace(1e3, 1e5, 60)
y = np.power(x, -2) * np.random.uniform(size=60)
plt.plot(x,y)

#Set logscale. Things work as expected in linear scale.
ax = plt.gca()
ax.set_xscale("log")
ax.set_yscale("log")

#IF THIS IS SET TO A LARGER INTERVAL, I.E. FROM 1E-10 TO 1E-7, 
#THEN THE ONLY YTICK PRESENT IS THE ONE I SET. FOR SMALLER VALUES,
#SUCH AS THE ONE HERE, I DO HAVE MORE TICKS APART FROM THE SELECTED ONE
ax.set_ylim(5e-8, 1e-7)
ax.set_yticks([6.56e-8])
ax.set_yticklabels(["mytick"])
plt.show()

Actual outcome

When the interval in y_lim is small enough, I do have more ticks than the one I want to have. But when the interval is larger, only the one I selected is present.

Expected outcome

I would like to have only the ytick that I selected in ax.set_yticks displayed, no matter how large the interval is.

Additional information

No response

Operating system

No response

Matplotlib Version

3.3.4

Matplotlib Backend

No response

Python version

3.8.8

Jupyter version

No response

Installation

No response

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