Skip to content

Fix colorbar bad ticks #11556

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

Merged
merged 1 commit into from
Jul 4, 2018
Merged

Conversation

jklymak
Copy link
Member

@jklymak jklymak commented Jul 3, 2018

PR Summary

As noted in issue #11510, extra ticks can get into the colorbar that extend past the minimum or maximum due to the presence of the "extend='both/lower/upper'` kwarg. This fixes that issue for major ticks.

An enhancement would be to come up with a cb.minorticks_on function to colorbar that supplies the appropriately trimmed minor tick locator as well. That can be a further PR. But this really fixes a bug in the existing functionality...

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(seed=12345)
x = np.random.randn(20, 20)
fig, ax = plt.subplots()
im = ax.pcolormesh(x)

cbar = fig.colorbar(im, extend='both')
plt.show()

Before:

boo

After

boo

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer
Copy link
Contributor

anntzer commented Jul 3, 2018

I mentioned in a few places that it should really be the responsibility of the ticker to return ticks that are indeed between vmin and vmax (should perhaps start a metaissue on that :)); looks like this is yet another reason to require so. Won't block this quickfix of course but perhaps leave a comment that it doesn't address the root issue (so that we can remove this patch once the real fix above is implemented).

Copy link
Member

@efiring efiring left a comment

Choose a reason for hiding this comment

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

Good, thank you.

@jklymak
Copy link
Member Author

jklymak commented Jul 3, 2018

perhaps leave a comment that it doesn't address the root issue...

Well, the docstring of the classes explicitly state that they work around this limitation - the problem here was that I forgot to actually do it for _ColorbarAutoLocator in the original PR! Duh...

@jklymak jklymak force-pushed the fix-colorbar-bad-ticks branch 3 times, most recently from 1ef04eb to dc2fce2 Compare July 3, 2018 20:24
Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

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

Please squash.

Anyone can (including @jklymak ) can dismiss thing and merge once squashed and CI passes.

@jklymak jklymak force-pushed the fix-colorbar-bad-ticks branch from dc2fce2 to d5dae3c Compare July 4, 2018 03:56
@jklymak jklymak dismissed tacaswell’s stale review July 4, 2018 03:57

Squash done! Thanks!

@dstansby dstansby merged commit 145f35e into matplotlib:master Jul 4, 2018
@jklymak jklymak deleted the fix-colorbar-bad-ticks branch July 4, 2018 13:29
@jklymak
Copy link
Member Author

jklymak commented Jul 4, 2018

@meeseeksdev backport to v2.2.x

@lumberbot-app
Copy link

lumberbot-app bot commented Jul 4, 2018

There seem to be a conflict, please backport manually

@jklymak
Copy link
Member Author

jklymak commented Jul 4, 2018

probably not worth the backport wrigamarole...

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.

5 participants