8000 FIX: fix error in colorbar.get_ticks not having valid data by jklymak · Pull Request #12656 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

FIX: fix error in colorbar.get_ticks not having valid data #12656

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 2 commits into from
Oct 31, 2018

Conversation

jklymak
Copy link
Member
@jklymak jklymak commented Oct 28, 2018

PR Summary

After the colorer tick overhaul the function get_ticks was broken. This now works:

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt. subplots()

pc = ax.pcolormesh(np.random.rand(30, 30))
cb = fig.colorbar(pc)
np.testing.assert_allclose(cb.get_ticks(), [0.2, 0.4, 0.6, 0.8])
plt.show()

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 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

@jklymak jklymak added this to the v3.0.x milestone Oct 28, 2018
@@ -573,6 +574,13 @@ def set_ticks(self, ticks, update_ticks=True):

def get_ticks(self, minor=False):
"""Return the x ticks as a list of locations"""
if self._tick_data_values is None:
Copy link
Member

Choose a reason for hiding this comment

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

Not quite following the logic here. We populate self._tick_data_values via update_ticks() -> self._ticker but not if _use_auto_colorbar_locator. It seems that if we use self._tick_data_values to store the ticks of a fixed locator. However, this mechanism is quite hidden and seems intransparent.

Would it make sense, to either rename _tick_data_values to something like _fixed_tick_data_values or alternatively get rid of that local variable and obtain the value dynamically?

Copy link
Member Author

Choose a reason for hiding this comment

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

@timhoffm fixed.

We cannot (trivially) get the value automatically because in the old days, all colorbars went from 0-1, and then were labeled from vmin to vmax by hand. Some types of colorbars are still made that way, so long_axis.get_majorticklocs() returns a list of floats between 0 and 1.

I think a todo is to go back and make those old-style colorbars the same as the new style, so they are all done in data space, and then we can make this homogeneous. But for a point release, this gets things working again...

Copy link
Member Author

Choose a reason for hiding this comment

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

Anyway, added a comment, and changed the name of the private (I hope?) variable...

@jklymak jklymak mentioned this pull request Oct 29, 2018
@jklymak jklymak force-pushed the f0x-colorbars-get_ticks-error branch from a82abc5 to 15e4e79 Compare October 29, 2018 21:42
Copy link
Member
@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

Anybody can merge after CI pass.

@jklymak jklymak merged commit 27f9f3c into matplotlib:master Oct 31, 2018
@jklymak jklymak deleted the f0x-colorbars-get_ticks-error branch October 31, 2018 05:06
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Oct 31, 2018
dstansby added a commit that referenced this pull request Oct 31, 2018
…656-on-v3.0.x

Backport PR #12656 on branch v3.0.x (FIX: fix error in colorbar.get_ticks not having valid data)
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
0