Skip to content

ENH: call update_ticks before we return them to the user - #20345

Closed
jklymak wants to merge 2 commits into
matplotlib:masterfrom
jklymak:enh-updateticks-on-get
Closed

jklymak wants to merge 2 commits into
matplotlib:masterfrom
jklymak:enh-updateticks-on-get

Conversation

@jklymak

@jklymak jklymak commented Jun 2, 2021

Copy link
Copy Markdown
Member

PR Summary

Currently, get_x/yticks doesn't work until a draw is called. But we can update the ticks, so why not?

PR Checklist

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (run flake8 on changed files to check).
  • New features are documented, with examples if plot related.
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).
  • Conforms to Matplotlib style conventions (install flake8-docstrings and run flake8 --docstring-convention=all).
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).

@jklymak jklymak changed the title ENH: call updateticks before we return them to the user ENH: call update_ticks before we return them to the user Jun 2, 2021
@jklymak
jklymak marked this pull request as ready for review July 27, 2021 13:34
@jklymak jklymak added this to the v3.5.0 milestone Jul 27, 2021
@jklymak

jklymak commented Sep 14, 2021

Copy link
Copy Markdown
Member Author

This one is pretty basic; if someone asks for the ticks on an axis, I don't see why we would force them to do a whole draw...

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That this is so basic makes me suspicious: Why haven't we done such a simple thing before?

My first guess "we use it heavily in the codebase (and it thus might be a performance issue)" is not correct. Apart from one usage in SecondaryAxis this is only used in tests an a tutorial. Why? Because internally we use get_minorticklocs() and get_majorticklocs(). Since both of them are public API as well, they should have the same update state as get_ticklocs(). I.e. if we update that should happen in there.

Now, I'm not sure what the implication of that would be. _update_ticks() queries get_minorticklocs() and get_majorticklocs() so we'd need to have a closer look on that cyclic usage. It might also be the case that we should make the current get_major/minorticklocs private for internal use without update and have change the public variants to use updates.

Anyway I'm afraid only adding _update_ticks() here is too simple.

@jklymak

jklymak commented Sep 16, 2021

Copy link
Copy Markdown
Member Author

I'm actually confused now what prompted this. Going back to 3.3.0

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()

ax.plot(np.arange(100))
print(ax.xaxis.get_majorticklocs())
print(ax.xaxis.get_minorticklocs())
print(ax.get_xticks())

works as expected. So I'll close this until we can remember why this was an issue.

@jklymak jklymak closed this Sep 16, 2021
@QuLogic

QuLogic commented May 3, 2023

Copy link
Copy Markdown
Member

This was re-done by #23170, because it wasn't really working as stated above.

@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants