Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
VictorSeven opened this issue May 30, 2022 · 2 comments
Closed

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

VictorSeven opened this issue May 30, 2022 · 2 comments

Comments

@VictorSeven
Copy link

VictorSeven commented May 30, 2022

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

@oscargus
Copy link
Member

The additional ticks are minor ticks. You can turn them off by either ax.minorticks_off() to get rid of the ticks and the labels or by ax.set_yticklabels([], minor=True) to keep the ticks, but not the labels.

@jklymak jklymak added the Community support Users in need of help. label May 30, 2022
@jklymak
Copy link
Member

jklymak commented May 30, 2022

I appreciate this is confusing, but I don't think there is much we can do about this. I'm going to close.

@jklymak jklymak closed this as completed May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants