John Hunter wrote:
"Eric" == Eric Firing <[EMAIL PROTECTED]> writes:


    Eric> John Hunter wrote:
    >>>>>>> "Eric" == Eric Firing <[EMAIL PROTECTED]> writes:
    >>
    Eric> they will not be transparent.  If you need transparent
    Eric> masked regions, then try pcolor instead of imshow.  Pcolor
    Eric> plots nothing at all in masked cells.  Pcolormesh, on the
    Eric> other hand, is like imshow in plotting the assigned bad
    Eric> 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?

    Eric> John,

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

My confusion here was that cmap.set_bad() ignores the alpha part of the color spec; you have to set alpha explicitly with a kwarg. Maybe I will fix this some time. But, read on...


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.


You are partly right; alpha works fine with imshow. But there is a problem in a backend, specifically the agg draw_quad_mesh and/or DrawQaudMesh methods. This is where I originally ran into the problem, and the attached script illustrates it. The figure on-screen has erratic and incorrect behavior in the central rectangle of the second subplot, for which alpha is zero. Note what happens when you resize the window. The ps backend, using the backend_bases code for the quad mesh, works correctly, now that I fixed it--two of the vertices in each quad were originally reversed.

It seems that DrawQuadMesh is trying to go straight to a low-level agg function, and in the process something is being lost when alpha is zero, or any value less than 1; in the example, you can change the alpha to 0.5, for example, and you will still see the behavior when you resize the window.

I'm stumped.

Eric


from pylab import figure, show, nx, savefig
from matplotlib import cm

# 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

if 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

C = nx.rand(3,3)
mask = nx.zeros((3,3))
mask[1,1] = 1
C = nx.ma.masked_array(C, mask=mask)
fig2 = figure()


ax = fig2.add_subplot(2,1,1)
ax.set_axis_bgcolor('r')
l, = ax.plot(nx.arange(3))
l.set_zorder(2)
cmap = cm.get_cmap()
cmap.set_bad((0,0,0), alpha=1)  # presently can't simply set rgba directly
pc = ax.pcolormesh(C, cmap=cmap)
pc.set_zorder(3)
ax.set_title('middle alpha is one')

ax = fig2.add_subplot(2,1,2)
ax.set_axis_bgcolor('r')
l, = ax.plot(nx.arange(3))
l.set_zorder(2)
cmap = cm.get_cmap()
cmap.set_bad((0,0,0), alpha=0)
pc = ax.pcolormesh(C, cmap=cmap)
pc.set_zorder(3)
ax.set_title('middle alpha is zero')

savefig('pcmesh.ps')

show()




Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to