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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ def __init__(self, ax, cmap=None,
self.outline = None
self.patch = None
self.dividers = None
self._manual_tick_data_values = None

if ticklocation == 'auto':
ticklocation = 'bottom' if orientation == 'horizontal' else 'right'
Expand Down Expand Up @@ -573,7 +574,17 @@ def set_ticks(self, ticks, update_ticks=True):

def get_ticks(self, minor=False):
"""Return the x ticks as a list of locations"""
return self._tick_data_values
if self._manual_tick_data_values is None:
ax = self.ax
if self.orientation == 'vertical':
long_axis, short_axis = ax.yaxis, ax.xaxis
else:
long_axis, short_axis = ax.xaxis, ax.yaxis
return long_axis.get_majorticklocs()
else:
# We made the axes manually, the old way, and the ylim is 0-1,
# so the majorticklocs are in those units, not data units.
return self._manual_tick_data_values

def set_ticklabels(self, ticklabels, update_ticks=True):
"""
Expand Down Expand Up @@ -755,7 +766,7 @@ def _ticker(self, locator, formatter):
else:
eps = (intv[1] - intv[0]) * 1e-10
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
self._tick_data_values = b
self._manual_tick_data_values = b
ticks = self._locate(b)
formatter.set_locs(b)
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
Expand Down
10 changes: 10 additions & 0 deletions lib/matplotlib/tests/test_colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,13 @@ def test_colorbar_renorm():
cbar.update_normal(im)
assert np.isclose(cbar.vmin, z.min() * 1000)
assert np.isclose(cbar.vmax, z.max() * 1000)


def test_colorbar_get_ticks():
with rc_context({'_internal.classic_mode': False}):

fig, ax = plt. subplots()
np.random.seed(19680801)
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])
0