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

Skip to content

Commit a786cb1

Browse files
committed
Merge pull request #10 from jenshnielsen/powernormclip
Fix issue with clipping of Power Norm
2 parents c98a90d + e2c4219 commit a786cb1

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,8 @@ def __call__(self, value, clip=None):
11711171
res_mask = result.data < 0
11721172
if clip:
11731173
mask = ma.getmask(result)
1174-
val = ma.array(np.clip(result.filled(vmax), vmin, vmax),
1175-
mask=mask)
1174+
result = ma.array(np.clip(result.filled(vmax), vmin, vmax),
1175+
mask=mask)
11761176
resdat = result.data
11771177
resdat -= vmin
11781178
np.power(resdat, gamma, resdat)

lib/matplotlib/tests/test_colors.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ def test_PowerNorm():
6969
assert_equal(pnorm(a[2]), expected[2])
7070
assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:])
7171

72+
# Clip = True
73+
a = np.array([-0.5, 0, 1, 8, 16], dtype=np.float)
74+
expected = [0, 0, 0, 1, 1]
75+
pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True)
76+
assert_array_almost_equal(pnorm(a), expected)
77+
assert_equal(pnorm(a[0]), expected[0])
78+
assert_equal(pnorm(a[-1]), expected[-1])
79+
80+
# Clip = True at call time
81+
a = np.array([-0.5, 0, 1, 8, 16], dtype=np.float)
82+
expected = [0, 0, 0, 1, 1]
83+
pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False)
84+
assert_array_almost_equal(pnorm(a, clip=True), expected)
85+
assert_equal(pnorm(a[0], clip=True), expected[0])
86+
assert_equal(pnorm(a[-1], clip=True), expected[-1])
87+
7288

7389
def test_Normalize():
7490
norm = mcolors.Normalize()

0 commit comments

Comments
 (0)