How to highlight part of a matrix (or wash out the rest of it)

Hi,

I have a square matrix that I'm plotting with pcolormesh. I want to
highlight certain parts of it. For instance, I might want to
highlight rows and columns 4-20 and 67-80. I can get the opposite of
what I want by doing something like

pylab.axvspan(4,20,fc='white',lw=0.,alpha=0.15)
pylab.axvspan(67,80,fc='white',lw=0.,alpha=0.15)
pylab.axhspan(4,20,fc='white',lw=0.,alpha=0.15)
pylab.axhspan(67,80,fc='white',lw=0.,alpha=0.15)

but that makes it look like the regions I want to highlight are washed
out. I'd like the inverse, where I wash out everything else. How can
I do this?

My first thought was that I might be able to do something with a mask,
where I could plot the data once, then plot it again with a
semitransparent white mask over the parts I didn't want to highlight.

Here's some sample code where I tried to do that (this time masking
out some easy-to-calculate part of the matrix):

#!/usr/bin/env python
import pylab as P
import numpy as N

plotter = P.pcolormesh
plotterargs = {P.imshow:{'interpolation':'nearest','origin':'lower'},
               P.pcolormesh:{}}

n = 10
data = N.zeros((n,n))
for i in range(n):
    for j in range(n):
        data[i,j] = i*j
plotter(data,vmin=0,vmax=n*n,**plotterargs[plotter])

cmap = P.cm.jet
cmap.set_bad('white',alpha=0.5)
mask = data < 16
data = N.ma.masked_where(mask,data)
plotter(data,cmap=cmap,vmin=0,vmax=n*n,**plotterargs[plotter])
P.show()

If you run it, you'll see that the masked part just ends up grey.
However, if you set plotter to P.imshow, it looks like it pretty much
does what I want. So, I think I might be close to the answer. Can
someone help me figure it out?

Thanks,

-michael

···

--
Biophysics Graduate Student
Carlson Lab, University of Michigan
http://www.umich.edu/~mlerner http://lernerclan.net