From ba7bc0a71001482e3719afd2ac1dc9ffe165f8d6 Mon Sep 17 00:00:00 2001 From: Eric Firing Date: Mon, 2 Mar 2015 10:25:47 -1000 Subject: [PATCH] colorbar: edit tick locations based on vmin and vmax; closes #4181 --- lib/matplotlib/colorbar.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 2cc294ed4c40..c4caae295681 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -584,10 +584,13 @@ def _ticker(self): formatter.set_data_interval(*intv) b = np.array(locator()) + if isinstance(locator, ticker.LogLocator): + eps = 1e-10 + b = b[(b <= intv[1] * (1 + eps)) & (b >= intv[0] * (1 - eps))] + else: + eps = (intv[1] - intv[0]) * 1e-10 + b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)] ticks = self._locate(b) - inrange = (ticks > -0.001) & (ticks < 1.001) - ticks = ticks[inrange] - b = b[inrange] formatter.set_locs(b) ticklabels = [formatter(t, i) for i, t in enumerate(b)] offset_string = formatter.get_offset()