From: Eric Firing <efiring@ha...>  20090929 17:38:17

Dr. Phillip M. Feldman wrote: > After experimenting with colormaps for a while, I was able to make both > discrete (piecewiseconstant) and continuous (piecewiselinear) colormaps > work. Although colormaps can be created directly using > LinearSegmentedColormap from the matplotlib.colors package, this is a > tedious and errorprone process. So, I compiled a set of three interface > functions. (I wrote two of these myself, and got one from the SciPy > website). The two functions that I wrote permit one to define a discrete > (piecewiseconstant) and continuous (piecewiselinear) colormap directly via > a sequence of colors and a set of thresholds specified as lists. Each color > may be specified either via an RGB tuple or via an English color name known > to webcolors.name_to_rgb. I'm going to submit all of this to the matplotlib > developers forums in the hopes of getting it incorporated into matplotlib. Something I should have mentioned earlier: for the discrete case, one good option is to use a ListedColormap to make a map with only a few colors, and then use a BoundaryNorm to handle the mapping from data values to colors. See http://matplotlib.sourceforge.net/examples/pylab_examples/image_masked.html?highlight=image_masked for a BoundaryNorm example. Unfortunately, we don't have an example of using it with a ListedColormap, but it should be straigtforward; the key point is to set the BoundaryNorm ncolors kwarg to match the actual number of colors in the colormap. Eric 