John, Something like this might be what you want:
from pylab import * import matplotlib.numerix.ma as ma import matplotlib.colors as colors xx = rand(10,15) xxx = (xx*15 - 5).astype(Int) xxx = ma.masked_where(xxx < 0, xxx) xxx.set_fill_value(-1) #(not necessary) cmap = colors.ListedColormap(('r', 'g', 'b', 'c', 'y', 'm', 'k', '0.3', '0.5', '0.7')) #cmap.set_bad((1,1,1,0)) # setting alpha to zero does not work, at least # for imshow im = imshow(xxx, interpolation='nearest', cmap=cmap, norm=colors.no_norm()) cb = colorbar(shrink=0.6) What we are doing here is making a custom colormap from a list of colors (using any valid mpl color specification), and then indexing directly into it with values from a (masked) integer array. Note the use of "norm=colors.no_norm()" so that the array values are passed directly to the colormap as integers. Caution: the colorbar command works correctly in this example only with the modifications that I committed to svn a few minutes ago. As noted, the masked regions will have a specified color; they will not be transparent. If you need transparent masked regions, then try pcolor instead of imshow. Pcolor plots nothing at all in masked cells. Pcolormesh, on the other hand, is like imshow in plotting the assigned bad color and in using a single alpha for everything. Eric John Pye wrote: > Hi all > > I have some data with enumerated values in an array. Values are like > 1,2,7,9 spread around in the array. I want to plot those values so that > I can see the 'regions' in my data, then I want to overlay this with > some contour lines drawn from other data. > > I want to be able to specify the colors for each of the enumerated > values, as they need to be consistent throughout my work. My array of > enumerated values is *masked* so that there are areas where I don't want > to show anything (this would plot as transparent pixels). > > Has anyone got suggestions on the best way of doing this? It seems that > the technique in > http://www.scipy.org/Cookbook/Matplotlib/Plotting_Images_with_Special_Values > might be overkill, right? It also seemed that it had some problems with > masked arrays. > > Cheers > > JP > _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users