SourceForge logo
SourceForge logo
Menu

matplotlib-devel

From: Eric F. <ef...@ha...> - 2006年06月24日 07:50:21
Attachments: alpha_test.py
John Hunter wrote:
>>>>>>"Eric" == Eric Firing <ef...@ha...> writes:
> 
> 
> Eric> John Hunter wrote:
> >>>>>>> "Eric" == Eric Firing <ef...@ha...> 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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /