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

Skip to content

Commit ab34279

Browse files
jklymakQuLogic
andcommitted
FIX: process lists for inverse norms
Co-authored-by: QuLogic <[email protected]>
1 parent a5ea869 commit ab34279

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/matplotlib/colors.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,12 +1449,14 @@ def inverse(self, value):
14491449
t_vmin, t_vmax = self._trf.transform([self.vmin, self.vmax])
14501450
if not np.isfinite([t_vmin, t_vmax]).all():
14511451
raise ValueError("Invalid vmin or vmax")
1452+
value, is_scalar = self.process_value(value)
14521453
rescaled = value * (t_vmax - t_vmin)
14531454
rescaled += t_vmin
1454-
return (self._trf
1455-
.inverted()
1456-
.transform(rescaled)
1457-
.reshape(np.shape(value)))
1455+
value = (self._trf
1456+
.inverted()
1457+
.transform(rescaled)
1458+
.reshape(np.shape(value)))
1459+
return value[0] if is_scalar else value
14581460

14591461
Norm.__name__ = base_norm_cls.__name__
14601462
Norm.__qualname__ = base_norm_cls.__qualname__

lib/matplotlib/tests/test_colors.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,17 @@ def test_LogNorm():
460460
assert_array_equal(ln([1, 6]), [0, 1.0])
461461

462462

463+
def test_LogNorm_inverse():
464+
"""
465+
Test that lists work, and that the inverse works
466+
"""
467+
norm = mcolors.LogNorm(vmin=0.1, vmax=10)
468+
assert_array_almost_equal(norm([0.5, 0.4]), [0.349485, 0.30103])
469+
assert_array_almost_equal([0.5, 0.4], norm.inverse([0.349485, 0.30103]))
470+
assert_array_almost_equal(norm(0.4), [0.30103])
471+
assert_array_almost_equal([0.4], norm.inverse([0.30103]))
472+
473+
463474
def test_PowerNorm():
464475
a = np.array([0, 0.5, 1, 1.5], dtype=float)
465476
pnorm = mcolors.PowerNorm(1)

0 commit comments

Comments
 (0)