Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FIX: fix logic for FixedLocator set_ticklabels #21485

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
wants to merge 2 commits into from

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Oct 28, 2021

PR Summary

Fixes an inconsistency noted in #20989

fig, ax = plt.subplots()

ax.set_xlim(0, 1)
ax.xaxis.set_major_locator(FixedLocator(np.linspace(0, 1, 51), nbins=10))
ax.set_xticklabels(ax.get_xticklabels())
plt.show()

gives a value error currently because the number of ticks is actually set by nbins-1, not by the number of levels. At the minimum the error message is confusing!

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 marked this pull request as draft October 28, 2021 13:14
@jklymak
Copy link
Member Author

jklymak commented Oct 28, 2021

OK, @efiring, can you explain to me why this breaks test_subsampled_ticklabels?

fig, ax = plt.subplots()
ax.plot(np.arange(10))
ax.xaxis.set_ticks(np.arange(10) + 0.1)
ax.locator_params(nbins=5)
ax.xaxis.set_ticklabels([c for c in "bcdefghijk"])
plt.draw()
labels = [t.get_text() for t in ax.xaxis.get_ticklabels()]
assert labels == ['b', 'd', 'f', 'h', 'j']

do we really want set_ and get_ to be asymmetric like this?

@efiring
Copy link
Member

efiring commented Oct 28, 2021

The problem is that get_ticklabels and set_ticklabels are both defined to return the visible tick labels, so subsetting reduces their number. I don't see how this can reasonably be changed, or that it should be changed. But maybe I don't understand your question.

@neutrinoceros
Copy link
Contributor

neutrinoceros commented Oct 29, 2021

fix #20989 (I see the issue wasn't linked already)

edit: oops, I thought that would work but it didn't. Can anyone with permission link the issue ?

@jklymak
Copy link
Member Author

jklymak commented Oct 29, 2021

@neutrinoceros as you can see, this "fix" breaks other tests. @efiring and I discussed briefly on the call, and agree that we can't really fix this. The regression came in only for colorbar just because colorbars are now "normal" axes wrt to locators and formatters. We are sorry this broke, but it was never really supposed to work ;-)

@jklymak jklymak closed this Oct 29, 2021
@jklymak jklymak deleted the fix-ticklab-fixedloc branch October 29, 2021 09:01
@neutrinoceros
Copy link
Contributor

fine by me ! Then I suppose we could close the issue as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants