From e1a8687f96aca782a5440c02bcddf583d1c98d17 Mon Sep 17 00:00:00 2001 From: Arjen van Elteren Date: Mon, 26 Oct 2015 14:18:27 +0100 Subject: [PATCH 1/3] fix for issue #5201, empty extension triangle for vmin < 1.0 --- lib/matplotlib/colorbar.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 82d5a04f7341..e0239c6bc5af 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -674,11 +674,12 @@ def _process_values(self, b=None): b = self.norm.inverse(self._uniform_y(self.cmap.N + 1)) if self._extend_lower(): - b[0] = b[0] - 1 + b[0] = 0.9 * b[0] if self._extend_upper(): - b[-1] = b[-1] + 1 + b[-1] = 1.1 * b[-1] self._process_values(b) + def _find_range(self): ''' Set :attr:`vmin` and :attr:`vmax` attributes to the first and @@ -820,6 +821,7 @@ def _mesh(self): X[-1, :] = 0.5 return X, Y + def _locate(self, x): ''' Given a set of color data values, return their From ba5123cb89676fe149d77161f2db3f21f3129ed7 Mon Sep 17 00:00:00 2001 From: Arjen van Elteren Date: Mon, 26 Oct 2015 14:20:18 +0100 Subject: [PATCH 2/3] fix for issue #5201, empty extension triangle for vmin < 1.0 --- lib/matplotlib/colorbar.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index e0239c6bc5af..ad50641e6d56 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -679,7 +679,6 @@ def _process_values(self, b=None): b[-1] = 1.1 * b[-1] self._process_values(b) - def _find_range(self): ''' Set :attr:`vmin` and :attr:`vmax` attributes to the first and @@ -821,7 +820,6 @@ def _mesh(self): X[-1, :] = 0.5 return X, Y - def _locate(self, x): ''' Given a set of color data values, return their From 345dad1b8ef39ebeb76ce339e5a05c1dbe38d18b Mon Sep 17 00:00:00 2001 From: Arjen van Elteren Date: Mon, 26 Oct 2015 17:14:50 +0100 Subject: [PATCH 3/3] fix for issue #5201, added test case --- lib/matplotlib/tests/test_colorbar.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_colorbar.py b/lib/matplotlib/tests/test_colorbar.py index de7decb6ec62..06b79e351a6f 100644 --- a/lib/matplotlib/tests/test_colorbar.py +++ b/lib/matplotlib/tests/test_colorbar.py @@ -11,9 +11,11 @@ import matplotlib.pyplot as plt from matplotlib import rcParams from matplotlib.colors import BoundaryNorm +from matplotlib.colors import LogNorm from matplotlib.cm import get_cmap from matplotlib import cm from matplotlib.colorbar import ColorbarBase +from nose.tools import assert_greater_equal def _get_cmap_norms(): @@ -254,7 +256,16 @@ def test_colorbarbase(): ax = plt.gca() ColorbarBase(ax, plt.cm.bone) - +@cleanup +def test_colorbar_lognorm_extension(): + # Issue #5201: empty triangle plotted + # for logarithmic colorbar with vmin < 1.0 + ax = plt.gca() + + cb = ColorbarBase(ax, norm=LogNorm(vmin=1, vmax=1000.0), orientation='vertical', extend='both') + + assert_greater_equal(cb._values[0], 0.0) + @image_comparison( baseline_images=['colorbar_closed_patch'], remove_text=True)