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

Skip to content

Commit c98a90d

Browse files
committed
BUG : fix PowerNorm with scalars
closes #4053
1 parent 36a7a21 commit c98a90d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/matplotlib/colors.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,7 @@ def __call__(self, value, clip=None):
11681168
elif vmin == vmax:
11691169
result.fill(0)
11701170
else:
1171+
res_mask = result.data < 0
11711172
if clip:
11721173
mask = ma.getmask(result)
11731174
val = ma.array(np.clip(result.filled(vmax), vmin, vmax),
@@ -1176,8 +1177,9 @@ def __call__(self, value, clip=None):
11761177
resdat -= vmin
11771178
np.power(resdat, gamma, resdat)
11781179
resdat /= (vmax - vmin) ** gamma
1180+
11791181
result = np.ma.array(resdat, mask=result.mask, copy=False)
1180-
result[value < 0] = 0
1182+
result[res_mask] = 0
11811183
if is_scalar:
11821184
result = result[0]
11831185
return result

lib/matplotlib/tests/test_colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import six
55

6-
from nose.tools import assert_raises
6+
from nose.tools import assert_raises, assert_equal
77

88
import numpy as np
99
from numpy.testing.utils import assert_array_equal, assert_array_almost_equal
@@ -62,9 +62,11 @@ def test_PowerNorm():
6262
assert_array_almost_equal(norm(a), pnorm(a))
6363

6464
a = np.array([-0.5, 0, 2, 4, 8], dtype=np.float)
65-
expected = [0, 0, 1./16, 1./4, 1]
65+
expected = [0, 0, 1/16, 1/4, 1]
6666
pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8)
6767
assert_array_almost_equal(pnorm(a), expected)
68+
assert_equal(pnorm(a[0]), expected[0])
69+
assert_equal(pnorm(a[2]), expected[2])
6870
assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])
6971

7072

0 commit comments

Comments
 (0)