Skip to content
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
2 changes: 1 addition & 1 deletion examples/pylab_examples/demo_bboximage.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
a = np.linspace(0, 1, 256).reshape(1, -1)
a = np.vstack((a, a))

maps = sorted(m for m in plt.cm.datad if not m.endswith("_r"))
maps = sorted(m for m in plt.cm.cmap_d if not m.endswith("_r"))
#nmaps = len(maps) + 1

#fig.subplots_adjust(top=0.99, bottom=0.01, left=0.2, right=0.99)
Expand Down
11 changes: 5 additions & 6 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,8 @@ def get_cmap(name=None, lut=None):
returned.

If *lut* is not None it must be an integer giving the number of
entries desired in the lookup table, and *name* must be a
standard mpl colormap name with a corresponding data dictionary
in *datad*.
entries desired in the lookup table, and *name* must be a standard
mpl colormap name.
"""
if name is None:
name = mpl.rcParams['image.cmap']
Expand All @@ -159,12 +158,12 @@ def get_cmap(name=None, lut=None):
if name in cmap_d:
if lut is None:
return cmap_d[name]
elif name in datad:
return _generate_cmap(name, lut)
else:
return cmap_d[name]._resample(lut)
else:
raise ValueError(
"Colormap %s is not recognized. Possible values are: %s"
% (name, ', '.join(cmap_d.keys())))
% (name, ', '.join(sorted(cmap_d.keys()))))


class ScalarMappable(object):
Expand Down
18 changes: 18 additions & 0 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,12 @@ def is_gray(self):
return (np.alltrue(self._lut[:, 0] == self._lut[:, 1]) and
np.alltrue(self._lut[:, 0] == self._lut[:, 2]))

def _resample(self, lutsize):
"""
Return a new color map with *lutsize* entries.
"""
raise NotImplementedError()


class LinearSegmentedColormap(Colormap):
"""Colormap objects based on lookup tables using linear segments.
Expand Down Expand Up @@ -772,6 +778,12 @@ def from_list(name, colors, N=256, gamma=1.0):

return LinearSegmentedColormap(name, cdict, N, gamma)

def _resample(self, lutsize):
"""
Return a new color map with *lutsize* entries.
"""
return LinearSegmentedColormap(self.name, self._segmentdata, lutsize)


class ListedColormap(Colormap):
"""Colormap object generated from a list of colors.
Expand Down Expand Up @@ -836,6 +848,12 @@ def _init(self):
self._isinit = True
self._set_extremes()

def _resample(self, lutsize):
"""
Return a new color map with *lutsize* entries.
"""
return ListedColormap(self.name, self.colors, lutsize)


class Normalize(object):
"""
Expand Down