This example may be instructive: it takes a list of colors and creates
a colormap that interpolates smoothly between them from normalized
But yes, a tutorial on the sphinx site would be great (at the sprint
yesterday one of the students wrote a nice image tut but I haven't
gotten it from him yet for upload)
def from_list(name, colors, N=256):
Make a linear segmented colormap with *name* from a sequence
of *colors* which evenly transitions from colors at val=1
to colors[-1] at val=1. N is the number of rgb quantization
ncolors = len(colors)
vals = np.linspace(0., 1., ncolors)
cdict = dict(red=, green=, blue=)
for val, color in zip(vals, colors):
r,g,b = colorConverter.to_rgb(color)
cdict['red'].append((val, r, r))
cdict['green'].append((val, g, g))
cdict['blue'].append((val, b, b))
return LinearSegmentedColormap(name, cdict, N)
On Sun, Aug 23, 2009 at 1:24 PM, Eric Firing<efiring@...202...> wrote:
Dr. Phillip M. Feldman wrote:
I've been trying to understand how colormaps work. I've been through the
Matplotlib User's Guide (Release 0.98.6svn, dated June 14, 2009), but the
section on colormaps has not yet been written. If anyone can point me to
This is my fault; I need to write that.
documentation or provide an explanation, I'd be grateful.
This may help:
Beware: the posted docs are current, so may include functions that are
not in the version of mpl you have installed.
If you search for "cmap" using the search box in the doc webpage
sidebar, you will get many more examples of the use of colormaps.
Browsing these examples may be the quickest way of getting the basic
ideas of how cmaps (and their partners, norms) are used.
Looking at the source code is also helpful.