I have committed to CVS a set of changes that I think will address recent requests by Jordan and Gerald, and will be of more general use as well. From the CHANGELOG:
2005-11-27 Multiple changes in cm.py, colors.py, figure.py, image.py,
contour.py, contour_demo.py; new _cm.py, examples/image_masked.py.
1) Separated the color table data from cm.py out into
a new file, _cm.py, to make it easier to find the actual
code in cm.py and to add new colormaps. Also added
some line breaks to the color data dictionaries. Everything
from _cm.py is imported by cm.py, so the split should be
2) Enabled automatic generation of a colormap from
a list of colors in contour; see modified
3) Support for imshow of a masked array, with the
ability to specify colors (or no color at all) for
masked regions, and for regions that are above or
below the normally mapped region. See
4) In support of the above, added two new classes,
ListedColormap, and no_norm, to colors.py, and modified
the Colormap class to include common functionality. Added
a clip kwarg to the normalize class. Reworked color
handling in contour.py, especially in the ContourLabeller
With one very subtle exception, I don't think any default behaviors have been changed, so the changes should be entirely non-disruptive.
That one exception is that in the original color mapping scheme, the last color was essentially never used. Consider an extreme case: a colormap with two entries. Suppose the image data ranged from 0 to 1. All values except exactly 1.0 were mapped to the first color, and only that upper limit value was mapped to the second color. As I have changed colors.py, values from 0.0 up to 0.5 will get the first color, and values from 0.5 through 1.0 will get the second. I think this is what a user would expect, and the only reason it hasn't mattered is that with 256 colors in a continuous range, one can't see the difference.
The request from Jordan that is addressed here is the desire for precise color control in filled contouring. Now one can specify a list of colors in the "colors" kwarg, and they will be used to generate a colormap, which will then be used by colorbar. This is shown in a second plot added to examples/contourf_demo.py. (Jordan suggested a more extensive refactoring, which may indeed be a good idea; but I wanted to make these simpler changes before trying to think about anything more drastic.)
The request from Gerald was for easy handling of masked arrays in imshow. It was in the context of basemap, which I have not tested yet; but at least for pylab.imshow, the situation is now easy to handle. If changes to basemap are needed, they should be very simple, and I can do them later as needed. I think that the changes to colormapping that I made to support this will be useful much more widely, but I have made no attempt to track down the places where changes will be in order. I may make additional changes to contour, and I know I will need to change colorbar to fully support this. I think colorbar needs some more refactoring anyway, but I can't do it immediately, and I did not want to delay getting the other changes out for testing and, hopefully, productive use.