|
20 | 20 | import matplotlib.scale as mscale |
21 | 21 | from matplotlib.rcsetup import cycler |
22 | 22 | from matplotlib.testing.decorators import image_comparison, check_figures_equal |
23 | | -from matplotlib.colors import is_color_like, to_rgba_array |
| 23 | +from matplotlib.colors import is_color_like, to_rgba_array, ListedColormap |
24 | 24 |
|
25 | 25 |
|
26 | 26 | @pytest.mark.parametrize('N, result', [ |
@@ -248,6 +248,17 @@ def test_LinearSegmentedColormap_from_list_bad_under_over(): |
248 | 248 | assert mcolors.same_color(cmap.get_over(), "y") |
249 | 249 |
|
250 | 250 |
|
| 251 | +def test_colormap_with_alpha(): |
| 252 | + cmap = ListedColormap(["red", "green", ("blue", 0.8)]) |
| 253 | + cmap2 = cmap.with_alpha(0.5) |
| 254 | + # color is the same: |
| 255 | + vals = [0, 0.5, 1] # numeric positions that map to the listed colors |
| 256 | + assert_array_equal(cmap(vals)[:, :3], cmap2(vals)[:, :3]) |
| 257 | + # alpha of cmap2 is changed: |
| 258 | + assert_array_equal(cmap(vals)[:, 3], [1, 1, 0.8]) |
| 259 | + assert_array_equal(cmap2(vals)[:, 3], [0.5, 0.5, 0.5]) |
| 260 | + |
| 261 | + |
251 | 262 | def test_BoundaryNorm(): |
252 | 263 | """ |
253 | 264 | GitHub issue #1258: interpolation was failing with numpy |
|
0 commit comments