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

Skip to content

Commit 13edeab

Browse files
committed
Tests for FuncNorm added, and bug corrected in FuncNorm
1 parent 5373a98 commit 13edeab

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,6 @@ def __init__(self, f, finv=None,
964964
vmin=None, vmax=None, clip=False):
965965

966966
f, finv = FuncNorm._fun_parser([f, finv])
967-
968967
if finv is None:
969968
raise ValueError("Inverse function not provided")
970969

@@ -985,6 +984,7 @@ def __call__(self, value, clip=None):
985984
clip = self.clip
986985

987986
result, is_scalar = self.process_value(value)
987+
self.autoscale_None(result)
988988

989989
vmin = self.vmin
990990
vmax = self.vmax
@@ -996,7 +996,6 @@ def __call__(self, value, clip=None):
996996
resultnorm = (self._f(result) - self._f(vmin)) / \
997997
(self._f(vmax) - self._f(vmin))
998998

999-
self.autoscale_None(resultnorm)
1000999
return np.ma.array(resultnorm)
10011000

10021001
def inverse(self, value):

lib/matplotlib/tests/test_colors.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ def test_LogNorm():
155155
ln = mcolors.LogNorm(clip=True, vmax=5)
156156
assert_array_equal(ln([1, 6]), [0, 1.0])
157157

158+
def test_FuncNorm():
159+
# Testing limits using a string
160+
norm = mcolors.FuncNorm(f='log', vmin=0.01, vmax=2)
161+
assert_array_equal(norm([0.01, 2]), [0, 1.0])
162+
163+
# Testing limits using a string
164+
norm = mcolors.FuncNorm(f=lambda x: np.log10(x),
165+
finv=lambda x: 10.**(x), vmin=0.01, vmax=2)
166+
assert_array_equal(norm([0.01, 2]), [0, 1.0])
167+
168+
# Testing limits without vmin, vmax
169+
norm = mcolors.FuncNorm(f='log')
170+
assert_array_equal(norm([0.01, 2]), [0, 1.0])
171+
172+
# Testing intermediate values
173+
norm = mcolors.FuncNorm(f='log')
174+
assert_array_almost_equal(norm([0.01, 0.5, 2]), [0, 0.73835195870437, 1.0])
175+
158176

159177
def test_PowerNorm():
160178
a = np.array([0, 0.5, 1, 1.5], dtype=float)

0 commit comments

Comments
 (0)