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


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


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'},

n = 10
data = N.zeros((n,n))
for i in range(n):
    for j in range(n):
        data[i,j] = i*j

cmap =
mask = data < 16
data =,data)

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?




Biophysics Graduate Student
Carlson Lab, University of Michigan