Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0aa344b

Browse files
committed
TST/MNT fix errors for overlapping vmin, vcenter, vmax
1 parent 7999661 commit 0aa344b

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

lib/matplotlib/colors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ def __call__(self, value, clip=None):
10401040
# or vmax. We could error out if some stop points are
10411041
# overrun, but this lets things keep going...
10421042

1043-
if not np.all(np.diff(self._data_points) >= 0):
1043+
if not np.all(np.diff(self._data_points) > 0):
10441044
raise ValueError("data points must increase monotonically")
10451045
ind = np.where((self._data_points >= vmin) &
10461046
(self._data_points <= vmax))[0]
@@ -1154,8 +1154,8 @@ def __call__(value, clip=None):
11541154
super().__call(value, clip=clip)
11551155
except ValueError:
11561156
# improve the more general error message.
1157-
raise ValueError('vmin, vcenter, and vmax must '
1158-
'increment monotonically for DivergingNorm '
1157+
raise ValueError('vmin, vcenter, and vmax must increment '
1158+
'monotonically for DivergingNorm '
11591159
'to work.')
11601160

11611161

lib/matplotlib/tests/test_colors.py

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -270,26 +270,17 @@ def test_DivergingNorm_Odd():
270270

271271

272272
def test_DivergingNorm_VminEqualsVcenter():
273-
norm = mcolors.DivergingNorm(vmin=-2, vcenter=-2, vmax=2)
274-
vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
275-
expected = np.array([0.5, 0.625, 0.75, 0.875, 1.0])
276-
assert_array_equal(norm(vals), expected)
273+
vals = np.arange(50)
274+
with pytest.raises(ValueError):
275+
norm = mcolors.DivergingNorm(vmin=10, vcenter=10, vmax=20)
276+
norm(vals)
277277

278278

279279
def test_DivergingNorm_VmaxEqualsVcenter():
280-
norm = mcolors.DivergingNorm(vmin=-2, vcenter=2, vmax=2)
281-
vals = np.array([-2.0, -1.0, 0.0, 1.0, 1.999, 2.0])
282-
expected = np.array([0.0, 0.125, 0.25, 0.375, 0.499875, 1.0])
283-
assert_array_equal(norm(vals), expected)
284-
285-
286-
def test_DivergingNorm_VsAllEqual():
287-
v = 10
288-
mcolors.DivergingNorm = mcolors.DivergingNorm
289-
norm = mcolors.DivergingNorm(vmin=v, vcenter=v, vmax=v)
290-
vals = np.array([-2.0, -1.0, 0.0, 1.0, 2.0])
291-
expected = np.array([0.0, 0.0, 0.0, 0.0, 0.0])
292-
assert_array_equal(norm(vals), expected)
280+
vals = np.arange(50)
281+
with pytest.raises(ValueError):
282+
norm = mcolors.DivergingNorm(vmin=0, vcenter=10, vmax=10)
283+
norm(vals)
293284

294285

295286
def test_DivergingNorm_VminGTVcenter():

0 commit comments

Comments
 (0)