Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion 3 lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,8 @@ def _resample(self, lutsize):
"""
Return a new color map with *lutsize* entries.
"""
return ListedColormap(self.name, self.colors, lutsize)
colors = self(np.linspace(0, 1, lutsize))
return ListedColormap(colors, name=self.name)


class Normalize(object):
Expand Down
22 changes: 22 additions & 0 deletions 22 lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@
cleanup, knownfailureif)


def test_resample():
"""
Github issue #6025 pointed to incorrect ListedColormap._resample;
here we test the method for LinearSegmentedColormap as well.
"""
n = 101
colorlist = np.empty((n, 4), float)
colorlist[:, 0] = np.linspace(0, 1, n)
colorlist[:, 1] = 0.2
colorlist[:, 2] = np.linspace(1, 0, n)
colorlist[:, 3] = 0.7
lsc = mcolors.LinearSegmentedColormap.from_list('lsc', colorlist)
lc = mcolors.ListedColormap(colorlist)
lsc3 = lsc._resample(3)
lc3 = lc._resample(3)
expected = np.array([[0.0, 0.2, 1.0, 0.7],
[0.5, 0.2, 0.5, 0.7],
[1.0, 0.2, 0.0, 0.7]], float)
assert_array_almost_equal(lsc3([0, 0.5, 1]), expected)
assert_array_almost_equal(lc3([0, 0.5, 1]), expected)


def test_colormap_endian():
"""
Github issue #1005: a bug in putmask caused erroneous
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.