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

Skip to content

Commit ce1dcfd

Browse files
committed
Additional tests for colors.MultiNorm
1 parent 206c9b8 commit ce1dcfd

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
@@ -3247,7 +3247,7 @@ def __call__(self, value, clip=None):
32473247
clip = self.clip
32483248
else:
32493249
if not np.iterable(clip):
3250-
value = [value]*self.n_input
3250+
clip = [clip]*self.n_input
32513251

32523252
value = self._iterable_variates_in_data(value, self.n_input)
32533253
result = [n(v, clip=c) for n, v, c in zip(self.norms, value, clip)]
@@ -3276,8 +3276,10 @@ def autoscale(self, A):
32763276
with self.callbacks.blocked():
32773277
# Pause callbacks while we are updating so we only get
32783278
# a single update signal at the end
3279-
self.vmin = self.vmax = None
3280-
self.autoscale_None(A)
3279+
A = self._iterable_variates_in_data(A, self.n_input)
3280+
for n, a in zip(self.norms, A):
3281+
n.autoscale(a)
3282+
self._changed()
32813283

32823284
def autoscale_None(self, A):
32833285
"""

lib/matplotlib/tests/test_colors.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,3 +1734,44 @@ def test_colorizer_vmin_vmax():
17341734
assert ca.vmax == 3.0
17351735
assert ca.norm.vmin == 1.0
17361736
assert ca.norm.vmax == 3.0
1737+
1738+
1739+
def test_multi_norm():
1740+
# tests for mcolors.MultiNorm
1741+
1742+
# test wrong input
1743+
with pytest.raises(ValueError,
1744+
match="A MultiNorm must be assigned multiple norms"):
1745+
mcolors.MultiNorm("bad_norm_name")
1746+
with pytest.raises(ValueError,
1747+
match="Invalid norm str name"):
1748+
mcolors.MultiNorm(["bad_norm_name"])
1749+
1750+
# test get vmin, vmax
1751+
norm = mpl.colors.MultiNorm(['linear', 'log'])
1752+
norm.vmin = 1
1753+
norm.vmax = 2
1754+
assert norm.vmin[0] == 1
1755+
assert norm.vmin[1] == 1
1756+
assert norm.vmax[0] == 2
1757+
assert norm.vmax[1] == 2
1758+
1759+
# test call with clip
1760+
assert_array_equal(norm([3, 3], clip=False), [2.0, 1.584962500721156])
1761+
assert_array_equal(norm([3, 3], clip=True), [1.0, 1.0])
1762+
assert_array_equal(norm([3, 3], clip=[True, False]), [1.0, 1.584962500721156])
1763+
norm.clip = False
1764+
assert_array_equal(norm([3, 3]), [2.0, 1.584962500721156])
1765+
norm.clip = True
1766+
assert_array_equal(norm([3, 3]), [1.0, 1.0])
1767+
norm.clip = [True, False]
1768+
assert_array_equal(norm([3, 3]), [1.0, 1.584962500721156])
1769+
norm.clip = True
1770+
1771+
# test inverse
1772+
assert_array_almost_equal(norm.inverse([0.5, 0.5849625007211562]), [1.5, 1.5])
1773+
1774+
# test autoscale
1775+
norm.autoscale([[0, 1, 2, 3], [0.1, 1, 2, 3]])
1776+
assert_array_equal(norm.vmin, [0, 0.1])
1777+
assert_array_equal(norm.vmax, [3, 3])

0 commit comments

Comments
 (0)