From ee1fb54c7205150efa9bb55d4defc733de9b486a Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Tue, 11 Sep 2018 16:21:04 -0700 Subject: [PATCH 1/2] FIX: make sure all ticks show up for colorbar minor tick --- lib/matplotlib/colorbar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index d88fcedb65d4..a53ccb1eeb8f 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -267,7 +267,8 @@ def __call__(self): vmin = self._colorbar.norm.vmin vmax = self._colorbar.norm.vmax ticks = ticker.AutoMinorLocator.__call__(self) - return ticks[(ticks >= vmin) & (ticks <= vmax)] + rtol = (vmax - vmin) * 1e-10 + return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)] class _ColorbarLogLocator(ticker.LogLocator): From fbfa18ed3c7f56c90105749c59acf5003d28dd9c Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 12 Sep 2018 14:42:34 -0700 Subject: [PATCH 2/2] TST: make sure edge minor ticks are drawn --- lib/matplotlib/colorbar.py | 2 +- lib/matplotlib/tests/test_colorbar.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index a53ccb1eeb8f..0a2bfe1140ee 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -267,7 +267,7 @@ def __call__(self): vmin = self._colorbar.norm.vmin vmax = self._colorbar.norm.vmax ticks = ticker.AutoMinorLocator.__call__(self) - rtol = (vmax - vmin) * 1e-10 + rtol = (vmax - vmin) * 1e-10 return ticks[(ticks >= vmin - rtol) & (ticks <= vmax + rtol)] diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index 2230c20e7d2f..56a829418910 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -294,6 +294,15 @@ def test_colorbar_minorticks_on_off(): np.testing.assert_almost_equal(cbar.ax.yaxis.get_minorticklocs(), np.array([])) + im.set_clim(vmin=-1.2, vmax=1.2) + cbar.minorticks_on() + correct_minorticklocs = np.array([-1.2, -1.1, -0.9, -0.8, -0.7, -0.6, + -0.4, -0.3, -0.2, -0.1, 0.1, 0.2, + 0.3, 0.4, 0.6, 0.7, 0.8, 0.9, + 1.1, 1.2]) + np.testing.assert_almost_equal(cbar.ax.yaxis.get_minorticklocs(), + correct_minorticklocs) + def test_colorbar_autoticks(): # Test new autotick modes. Needs to be classic because