GitHub issue #6025 pointed to incorrect ListedColormap.resampled; here we test the method for LinearSegmentedColormap as well.
()
| 43 | |
| 44 | |
| 45 | def test_resampled(): |
| 46 | """ |
| 47 | GitHub issue #6025 pointed to incorrect ListedColormap.resampled; |
| 48 | here we test the method for LinearSegmentedColormap as well. |
| 49 | """ |
| 50 | n = 101 |
| 51 | colorlist = np.empty((n, 4), float) |
| 52 | colorlist[:, 0] = np.linspace(0, 1, n) |
| 53 | colorlist[:, 1] = 0.2 |
| 54 | colorlist[:, 2] = np.linspace(1, 0, n) |
| 55 | colorlist[:, 3] = 0.7 |
| 56 | lsc = mcolors.LinearSegmentedColormap.from_list( |
| 57 | 'lsc', colorlist, under='red', over='green', bad='blue') |
| 58 | lc = mcolors.ListedColormap(colorlist, under='red', over='green', bad='blue') |
| 59 | lsc3 = lsc.resampled(3) |
| 60 | lc3 = lc.resampled(3) |
| 61 | expected = np.array([[0.0, 0.2, 1.0, 0.7], |
| 62 | [0.5, 0.2, 0.5, 0.7], |
| 63 | [1.0, 0.2, 0.0, 0.7]], float) |
| 64 | assert_array_almost_equal(lsc3([0, 0.5, 1]), expected) |
| 65 | assert_array_almost_equal(lc3([0, 0.5, 1]), expected) |
| 66 | # Test over/under was copied properly |
| 67 | assert_array_almost_equal(lsc(np.inf), lsc3(np.inf)) |
| 68 | assert_array_almost_equal(lsc(-np.inf), lsc3(-np.inf)) |
| 69 | assert_array_almost_equal(lsc(np.nan), lsc3(np.nan)) |
| 70 | assert_array_almost_equal(lc(np.inf), lc3(np.inf)) |
| 71 | assert_array_almost_equal(lc(-np.inf), lc3(-np.inf)) |
| 72 | assert_array_almost_equal(lc(np.nan), lc3(np.nan)) |
| 73 | |
| 74 | |
| 75 | def test_monochrome(): |