|
From: John H. <jdh...@ac...> - 2004-05-21 14:43:25
|
>>>>> "Andrew" == Andrew Straw <str...@as...> writes:
Andrew> Hi all, I'd like use matplotlib to draw shapes on a
Andrew> transparent background using the Agg backend to save .png
Andrew> files. Is this possible?
Andrew> I've tried
Andrew> fig._figurePatch.set_alpha(0)
There is a vestigial limitation from the bad old days when we didn't
have an alpha channel. For polyons, there is no place holder for a
separate alpha channel for the edge and face. The way to do this
right is to simply replace all rgb instances throughout the library
with rgba, but this is a fair amount of work that touches the entire
library. What I am doing currently is sharing the alpha attribute
between edge and face for polygons.
So setting alpha=0 *should work. What backend and version are you
using? Rectangle calls gc.set_alpha before calling draw_polygon in
patches.Patch. In _backend_agg.RendererAgg.draw_polygon, the alpha
attribute for the face is taken from the edge which gets it from the
gc (around line 204 in _backend_agg). I say all this just because
from my read of the code *it should* work, and indeed, in my tests
f = figure(1, facecolor='r')
f._figurePatch.set_alpha(0.0)
does work for me using Agg and the latest matplotlib.
What backend and version are you using?
That said, the best way to do this is to add a frameon attribute for
figures, because this will be respected across backends including
those who don't understand alpha. This way you can say
f = figure(1, frameon=False)
I checked this into CVS.
JDH
Andrew> This seems to get halfway, but there's still (opaque)
Andrew> white drawn in the background.
Andrew> Is there a "recommended way", and, if so, what is it?
Andrew> Otherwise, can we improve matplotlib to allow drawing on
Andrew> transparent backgrounds?
Andrew> Cheers! Andrew
Andrew> -------------------------------------------------------
Andrew> This SF.Net email is sponsored by: Oracle 10g Get
Andrew> certified on the hottest thing ever to hit the
Andrew> market... Oracle 10g. Take an Oracle 10g class now, and
Andrew> we'll give you the exam FREE.
Andrew> http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click
Andrew> _______________________________________________
Andrew> Matplotlib-users mailing list
Andrew> Mat...@li...
Andrew> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
|