plotting an array of enumerated values

John Hunter wrote:

    >>
    > 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.
    >> I'm confused about the comments about alpha not working on
    >> imshow -- can you elaborate. On the agg backend at least, the
    >> alpha channel is respected in imshow, eg
    >> examples/layer_images.py. Is there a reason it does not (or
    >> should not) work in the masked example?

    > John,

    > I don't know why it doesn't work; I know only that in my
    > example, it doesn't work as I perhaps naively think it
    > should. My interpretation of alpha is that if alpha is zero
    > in any colored region, and if nothing else is drawn on top,
    > then the background should show through; that is, the r,g,b
    > values in the r,g,b,a tuple for a region should have no
    > effect if a is zero. If you uncomment
    > #cmap.set_bad((1,1,1,0) in my example, you will find that
    > the masked region is white; and if you change the rgb part
    > of that tuple, it takes on that color, regardless of alpha.

I'm not sure what is going on in your example, but this test case
shows that the alpha channel is respected. I made a red RGBA array
and set the alpha channel for the center to be transparent and it
behaves as expected: you can see the line through the transparent
region of the rectangle and the axes bgcolor shows through. I had to
make a small change to svn to make this work because the image wasn't
respecting the zorder (revision 2495). So the bug you are
experiencing is likely to be in the front-end code.

from pylab import figure, show, nx

# a red rectangle with a transparent center
X = nx.ones((20,20,4), nx.Float)
X[:,:,1] = 0
X[:,:,2] = 0
X[5:15,5:15,-1] = 0

fig = figure()
ax = fig.add_subplot(111)
l, = ax.plot(nx.arange(20))
l.set_zorder(2)
             
im = ax.imshow(X)
im.set_zorder(3) # put the image over the line
show()