Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_cmap_and_norm_from_levels_and_colors2():
clr = mcolors.colorConverter.to_rgba_array(colors)
bad = (0.1, 0.1, 0.1, 0.1)
no_color = (0.0, 0.0, 0.0, 0.0)
masked_value = 'masked value'

# Define the test values which are of interest.
# Note: levels are lev[i] <= v < lev[i+1]
Expand All @@ -131,38 +132,40 @@ def test_cmap_and_norm_from_levels_and_colors2():
2.25: clr[2],
3: clr[4],
3.5: clr[4],
np.ma.array(1, mask=True): bad}),
masked_value: bad}),

('min', -1, {-2: clr[0],
-1: clr[1],
2: clr[2],
2.25: clr[2],
3: no_color,
3.5: no_color,
np.ma.array(1, mask=True): bad}),
masked_value: bad}),

('max', -1, {-2: no_color,
-1: clr[0],
2: clr[1],
2.25: clr[1],
3: clr[3],
3.5: clr[3],
np.ma.array(1, mask=True): bad}),
masked_value: bad}),

('neither', -2, {-2: no_color,
-1: clr[0],
2: clr[1],
2.25: clr[1],
3: no_color,
3.5: no_color,
np.ma.array(1, mask=True): bad}),
masked_value: bad}),
]

for extend, i1, cases in tests:
cmap, norm = mcolors.from_levels_and_colors(levels, colors[0:i1],
extend=extend)
cmap.set_bad(bad)
for d_val, expected_color in sorted(cases.items()):
if d_val == masked_value:
d_val = np.ma.array(1, mask=True)
assert_array_equal(expected_color, cmap(norm([d_val]))[0],
'Wih extend={0!r} and data '
'value={1!r}'.format(extend, d_val))
Expand Down