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

Skip to content

Commit 120d696

Browse files
committed
Additional tests for colors.MultiNorm
1 parent 48eb32b commit 120d696

2 files changed

Lines changed: 46 additions & 3 deletions

File tree

lib/matplotlib/colors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3379,7 +3379,7 @@ def __call__(self, value, clip=None):
33793379
clip = self.clip
33803380
else:
33813381
if not np.iterable(clip):
3382-
value = [value]*self.n_input
3382+
clip = [clip]*self.n_input
33833383

33843384
value = self._iterable_variates_in_data(value, self.n_input)
33853385
result = [n(v, clip=c) for n, v, c in zip(self.norms, value, clip)]
@@ -3408,8 +3408,10 @@ def autoscale(self, A):
34083408
with self.callbacks.blocked():
34093409
# Pause callbacks while we are updating so we only get
34103410
# a single update signal at the end
3411-
self.vmin = self.vmax = None
3412-
self.autoscale_None(A)
3411+
A = self._iterable_variates_in_data(A, self.n_input)
3412+
for n, a in zip(self.norms, A):
3413+
n.autoscale(a)
3414+
self._changed()
34133415

34143416
def autoscale_None(self, A):
34153417
"""

lib/matplotlib/tests/test_colors.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,3 +1811,44 @@ def test_LinearSegmentedColormap_from_list_value_color_tuple():
18111811
cmap([value for value, _ in value_color_tuples]),
18121812
to_rgba_array([color for _, color in value_color_tuples]),
18131813
)
1814+
1815+
1816+
def test_multi_norm():
1817+
# tests for mcolors.MultiNorm
1818+
1819+
# test wrong input
1820+
with pytest.raises(ValueError,
1821+
match="A MultiNorm must be assigned multiple norms"):
1822+
mcolors.MultiNorm("bad_norm_name")
1823+
with pytest.raises(ValueError,
1824+
match="Invalid norm str name"):
1825+
mcolors.MultiNorm(["bad_norm_name"])
1826+
1827+
# test get vmin, vmax
1828+
norm = mpl.colors.MultiNorm(['linear', 'log'])
1829+
norm.vmin = 1
1830+
norm.vmax = 2
1831+
assert norm.vmin[0] == 1
1832+
assert norm.vmin[1] == 1
1833+
assert norm.vmax[0] == 2
1834+
assert norm.vmax[1] == 2
1835+
1836+
# test call with clip
1837+
assert_array_equal(norm([3, 3], clip=False), [2.0, 1.584962500721156])
1838+
assert_array_equal(norm([3, 3], clip=True), [1.0, 1.0])
1839+
assert_array_equal(norm([3, 3], clip=[True, False]), [1.0, 1.584962500721156])
1840+
norm.clip = False
1841+
assert_array_equal(norm([3, 3]), [2.0, 1.584962500721156])
1842+
norm.clip = True
1843+
assert_array_equal(norm([3, 3]), [1.0, 1.0])
1844+
norm.clip = [True, False]
1845+
assert_array_equal(norm([3, 3]), [1.0, 1.584962500721156])
1846+
norm.clip = True
1847+
1848+
# test inverse
1849+
assert_array_almost_equal(norm.inverse([0.5, 0.5849625007211562]), [1.5, 1.5])
1850+
1851+
# test autoscale
1852+
norm.autoscale([[0, 1, 2, 3], [0.1, 1, 2, 3]])
1853+
assert_array_equal(norm.vmin, [0, 0.1])
1854+
assert_array_equal(norm.vmax, [3, 3])

0 commit comments

Comments
 (0)