comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: help with transparent plot in version 8.2.2
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: help with transparent plot in version 8.2.2 [message #83623] Fri, 15 March 2013 14:05
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Thursday, March 14, 2013 12:57:47 PM UTC-6, David Fanning wrote:
> Teddy Allen writes:
>
>
>
>> Looks like using LAYOUT instead of POSITION worked! I wish I knew
>
>> why though...
>
>
>
> Yes, my general experience with function graphics is that there are
>
> always multiple ways to do something with the routines, only one of
>
> which actually works. It is left as an an exercise for the user to
>
> determine which one that is. The only pattern I've noticed is that the
>
> right answer is generally not the one recommended by whatever
>
> documentation you have found to read. :-)
>
>
>
> In defense of function graphics, however, I will say that the version in
>
> IDL 8.2.2 is the best yet, and I have noticed a significant speed-up in
>
> performance lately. I still find them a bit confounding and I chafe at
>
> these niggling "features" that *almost* allow you to do your work, but
>
> not quite. For example, I think I might be quite happy to switch to
>
> function graphics map projections if I could just label box axes
>
> appropriately and if they didn't insist on warping my image.
>
>
>
> Maybe by next year...
>
>
>
> Cheers,
>
>
>
> David
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Hi David,
As you point out, clear, simple reproduce cases will go a long way towards getting any shortcomings fixed. :-)
-Chris
Re: help with transparent plot in version 8.2.2 [message #83624 is a reply to message #83623] Fri, 15 March 2013 14:03 Go to previous message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
Hi Teddy,

I can explain this. In the docs for the TRANSPARENT keyword, there is a little-known sentence: "Set this keyword to an RGB value (a three-element vector of the form [R, G, B]) indicating which pixels in the output image should be made transparent. If this keyword is set to 1, the color of the lower left pixel in the image is used as the transparent color."

So, in your example with POSITION, you are putting the plot into the lower-left corner. So the pixel at [0,0] is actually black, which is unfortunately getting assigned as the transparent color!

The solution is to do p.Save, 'plot.png', TRANSPARENT=[255,255,255], which forces the transparent color to be white.

Hope this helps.

-Chris
ExelisVIS
Re: help with transparent plot in version 8.2.2 [message #83644 is a reply to message #83624] Thu, 14 March 2013 11:57 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Teddy Allen writes:

> Looks like using LAYOUT instead of POSITION worked! I wish I knew
> why though...

Yes, my general experience with function graphics is that there are
always multiple ways to do something with the routines, only one of
which actually works. It is left as an an exercise for the user to
determine which one that is. The only pattern I've noticed is that the
right answer is generally not the one recommended by whatever
documentation you have found to read. :-)

In defense of function graphics, however, I will say that the version in
IDL 8.2.2 is the best yet, and I have noticed a significant speed-up in
performance lately. I still find them a bit confounding and I chafe at
these niggling "features" that *almost* allow you to do your work, but
not quite. For example, I think I might be quite happy to switch to
function graphics map projections if I could just label box axes
appropriately and if they didn't insist on warping my image.

Maybe by next year...

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: help with transparent plot in version 8.2.2 [message #83647 is a reply to message #83644] Thu, 14 March 2013 11:29 Go to previous message
Teddy Allen is currently offline  Teddy Allen
Messages: 13
Registered: October 2010
Junior Member
On Thursday, March 14, 2013 9:05:43 AM UTC-4, Brian J. Daniel wrote:
> On Wednesday, March 13, 2013 11:42:42 PM UTC-4, Teddy Allen wrote:
>
>> In the past I was able to easily save any line plot with a transparent background simply by saving the plot as:
>
>>
>
>>
>
>>
>
>> plot.save,'transparent_plot.png',/TRANSPARENT
>
>>
>
>>
>
>>
>
>> Unfortunately, this does not seem to work anymore if used with the plot function with the POSITION keyword. The following lines of code do not produce an expected transparent .png .
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> ;;;; GPCP2b is a 16,16,12 array
>
>>
>
>> ;;;; Lines below produce a 12 month annual rainfall time series for a 16x16 grid
>
>>
>
>> ;;;; in the Caribbean.
>
>>
>
>>
>
>>
>
>> DIM=16.
>
>>
>
>> SC=1/DIM
>
>>
>
>> p = plot(GPCP2b[0,0,*],position=[0,0,SC,SC],$
>
>>
>
>> yrange=[0,max(GPCP2b)], XSHOWTEXT=0,$
>
>>
>
>> YSHOWTEXT=0, color='black',TRANSPARENCY=0)
>
>>
>
>>
>
>>
>
>> for i = 0,15 do begin
>
>>
>
>> for j =0,15 do begin
>
>>
>
>> p1=plot(GPCP2b[i,j,*],position=[SC*i,SC*j,SC*(i+1),SC*(j+1)] $,/current,
>
>>
>
>> yrange=[0,max(GPCP2b)], XSHOWTEXT=0, YSHOWTEXT=0, color='black')
>
>>
>
>> endfor
>
>>
>
>> endfor
>
>>
>
>> p1.save,'C:\datasets\testTRANS.png',/TRANSPARENT
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> I have tried various combinations of using BACKGROUND_COLOR and BACKGROUND_TRANSPARENCY in the plot commands, but nothing works.
>
>>
>
>>
>
>>
>
>> This produces a transparent plot:
>
>>
>
>> p = plot(GPCP2b[0,0,*],yrange=[0,max(GPCP2b)], XSHOWTEXT=0, YSHOWTEXT=0, $ color='black')
>
>>
>
>> p.save,'C:\datasets\testTRANS.png',/TRANSPARENT
>
>>
>
>>
>
>>
>
>> However, this DOES NOT:
>
>>
>
>> p = plot(GPCP2b[0,0,*],position=[0,0,SC,SC],yrange=[0,max(GPCP2b )],$ XSHOWTEXT=0,YSHOWTEXT=0,color='black')
>
>>
>
>> p.save,'C:\datasets\testTRANS.png',/TRANSPARENT
>
>>
>
>>
>
>>
>
>>
>
>>
>
>> Any tips would be greatly appreciated. Thank you.
>
>>
>
>> teddy
>
>
>
> Have you tried using the Layout keyword instead of Position?

Looks like using LAYOUT instead of POSITION worked! I wish I knew why though...Thank you!
Re: help with transparent plot in version 8.2.2 [message #83650 is a reply to message #83647] Thu, 14 March 2013 10:12 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Teddy Allen writes:

> Very strange, I do NOT get a transparent images when I include the POSITION keyword.
>
> p = plot(GPCP2b[0,0,*],position=[0,0,SC,SC],yrange=[0,max(GPCP2b )],XSHOWTEXT=0,YSHOWTEXT=0,color='black',TRANSPARENCY=0)
> p.save,'C:\datasets\testPOSITION_ONE.png',/TRANSPARENT
>
> DO NOT RETURN TRANSPARENT IMAGE, but the following DOES:
> p = plot(GPCP2b[0,0,*],yrange=[0,max(GPCP2b)],XSHOWTEXT=0,YSHOWT EXT=0,color='black',TRANSPARENCY=0)
> p.save,'C:\datasets\testPOSITION_ONE.png',/TRANSPARENT

Well, I can't plot your data, obviously. Can you give me an example that
fails that I can actually test?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: help with transparent plot in version 8.2.2 [message #83651 is a reply to message #83650] Thu, 14 March 2013 10:00 Go to previous message
Teddy Allen is currently offline  Teddy Allen
Messages: 13
Registered: October 2010
Junior Member
On Thursday, March 14, 2013 9:40:12 AM UTC-4, David Fanning wrote:
> Teddy Allen writes:
>
>
>
>> In the past I was able to easily save any line plot with a transparent background simply by saving the plot as:
>
>>
>
>> plot.save,'transparent_plot.png',/TRANSPARENT
>
>>
>
>> Unfortunately, this does not seem to work anymore if used with the plot function with the POSITION keyword. The following lines of code do not produce an expected transparent .png .
>
>
>
> I get transparent plots with or without the POSITION keyword on my
>
> Windows machine in IDL 8.2.2.
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
>
> Sepore ma de ni thue. ("Perhaps thou speakest truth.")

Very strange, I do NOT get a transparent images when I include the POSITION keyword.

p = plot(GPCP2b[0,0,*],position=[0,0,SC,SC],yrange=[0,max(GPCP2b )],XSHOWTEXT=0,YSHOWTEXT=0,color='black',TRANSPARENCY=0)
p.save,'C:\datasets\testPOSITION_ONE.png',/TRANSPARENT

DO NOT RETURN TRANSPARENT IMAGE, but the following DOES:
p = plot(GPCP2b[0,0,*],yrange=[0,max(GPCP2b)],XSHOWTEXT=0,YSHOWT EXT=0,color='black',TRANSPARENCY=0)
p.save,'C:\datasets\testPOSITION_ONE.png',/TRANSPARENT
Re: help with transparent plot in version 8.2.2 [message #83658 is a reply to message #83651] Thu, 14 March 2013 06:40 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Teddy Allen writes:

> In the past I was able to easily save any line plot with a transparent background simply by saving the plot as:
>
> plot.save,'transparent_plot.png',/TRANSPARENT
>
> Unfortunately, this does not seem to work anymore if used with the plot function with the POSITION keyword. The following lines of code do not produce an expected transparent .png .

I get transparent plots with or without the POSITION keyword on my
Windows machine in IDL 8.2.2.

Cheers,

David


--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.idlcoyote.com/
Sepore ma de ni thue. ("Perhaps thou speakest truth.")
Re: help with transparent plot in version 8.2.2 [message #83659 is a reply to message #83658] Thu, 14 March 2013 06:05 Go to previous message
Brian Daniel is currently offline  Brian Daniel
Messages: 80
Registered: July 2009
Member
On Wednesday, March 13, 2013 11:42:42 PM UTC-4, Teddy Allen wrote:
> In the past I was able to easily save any line plot with a transparent background simply by saving the plot as:
>
>
>
> plot.save,'transparent_plot.png',/TRANSPARENT
>
>
>
> Unfortunately, this does not seem to work anymore if used with the plot function with the POSITION keyword. The following lines of code do not produce an expected transparent .png .
>
>
>
>
>
> ;;;; GPCP2b is a 16,16,12 array
>
> ;;;; Lines below produce a 12 month annual rainfall time series for a 16x16 grid
>
> ;;;; in the Caribbean.
>
>
>
> DIM=16.
>
> SC=1/DIM
>
> p = plot(GPCP2b[0,0,*],position=[0,0,SC,SC],$
>
> yrange=[0,max(GPCP2b)], XSHOWTEXT=0,$
>
> YSHOWTEXT=0, color='black',TRANSPARENCY=0)
>
>
>
> for i = 0,15 do begin
>
> for j =0,15 do begin
>
> p1=plot(GPCP2b[i,j,*],position=[SC*i,SC*j,SC*(i+1),SC*(j+1)] $,/current,
>
> yrange=[0,max(GPCP2b)], XSHOWTEXT=0, YSHOWTEXT=0, color='black')
>
> endfor
>
> endfor
>
> p1.save,'C:\datasets\testTRANS.png',/TRANSPARENT
>
>
>
>
>
>
>
> I have tried various combinations of using BACKGROUND_COLOR and BACKGROUND_TRANSPARENCY in the plot commands, but nothing works.
>
>
>
> This produces a transparent plot:
>
> p = plot(GPCP2b[0,0,*],yrange=[0,max(GPCP2b)], XSHOWTEXT=0, YSHOWTEXT=0, $ color='black')
>
> p.save,'C:\datasets\testTRANS.png',/TRANSPARENT
>
>
>
> However, this DOES NOT:
>
> p = plot(GPCP2b[0,0,*],position=[0,0,SC,SC],yrange=[0,max(GPCP2b )],$ XSHOWTEXT=0,YSHOWTEXT=0,color='black')
>
> p.save,'C:\datasets\testTRANS.png',/TRANSPARENT
>
>
>
>
>
> Any tips would be greatly appreciated. Thank you.
>
> teddy

Have you tried using the Layout keyword instead of Position?
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: cgPlotS and cgColorBar issues
Next Topic: setcurrent and buffer don't work together?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:37:19 PDT 2025

Total time taken to generate the page: 0.00540 seconds