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

Home » Public Forums » archive » Re: cgcolorbar problem in postscript
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: cgcolorbar problem in postscript [message #81945] Wed, 07 November 2012 08:29 Go to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Phillip M. Bitzer writes:

> Like David said, this is not a problem with the file or cgColorbar, but
> I don't think this is a "problem" exactly with Preview either - it seems
> to be an issue with aliasing.

Ah, thank you, Phillip. I'll add this to the article
I've written about this.

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: cgcolorbar problem in postscript [message #81947 is a reply to message #81945] Wed, 07 November 2012 08:22 Go to previous messageGo to next message
Phillip M. Bitzer is currently offline  Phillip M. Bitzer
Messages: 7
Registered: September 2012
Junior Member
Like David said, this is not a problem with the file or cgColorbar, but
I don't think this is a "problem" exactly with Preview either - it seems
to be an issue with aliasing. Consider the program below, which is
similar to yours (note I don't load in a color bar, rather I specify the
RGB palette). After producing the eps file, open it in Preview. You'll
probably see the graduated colors, which I think is what you are reporting.

If you go to Preferences->PDF, and toggle the Check box for "Smooth text
and line art", then you will see your discrete color bar reappear. The
text won't look as nice, however. This is an issue with the default
aliasing used by Preview - smoothing introduces the graduated colors you
see.

For reference, here's what I see:
https://www.dropbox.com/s/rvax832ot0t8l2b/colorbar_nosmooth. png

https://www.dropbox.com/s/2b2k8jj1taifpk0/colorbar_smooth.pn g

PRO pmbtest, Do_Ps = do_ps

colors = [ 'hot pink', 'indian red', 'dark green', 'green', $
'sky blue', 'cadet blue', 'grey', 'blue', 'purple', 'red']

n_color = N_ELEMENTS(colors)

do_ps = KEYWORD_SET(do_ps)
IF do_ps THEN BEGIN
PS_START, filename='test.eps', /ENCAP, /NOMATCH, $
XSIZE=6, YSIZE=2, /INCHES
ENDIF ELSE cgERASE, 'white'

rgb = cgCOLOR(colors, /TRIPLE)

;display the colorbar
cgCOLORBAR, /DISCRETE, NCOLORS=n_color, PALETTE = rgb, POSITION=[0.1,
0.2, 0.9, 0.9]

IF do_ps THEN PS_END

END
Re: cgcolorbar problem in postscript [message #81968 is a reply to message #81947] Mon, 05 November 2012 08:47 Go to previous messageGo to next message
Ailie is currently offline  Ailie
Messages: 2
Registered: November 2012
Junior Member
Thank you! That is EXACTLY what the problem is! The issue was with Preview.app on the Mac (I also tried with Powerpoint for Mac and same issue). I'll switch to a native viewer like ghost view from now on.



On Monday, November 5, 2012 4:42:43 AM UTC-8, David Fanning wrote:
> Ailie writes:
>
>
>
>> I'm trying to make a discrete colorbar for an image and plotting straight to postscript. But cgcolorbar.pro is giving some unexpected behaviour.
>
>>
>
>> Basically, I'm trying to plot a discrete colorbar (using the DISCRETE keyword) with 6 colors in postscript. If I plot in using the X device, it behaves as I expect, producing a colorbar with six, distinct divisions, each division filled with a solid block of color.
>
>>
>
>> But when I plot in postscript, my resulting colorbar most definitely has more than 6 colors and instead appears to have graduating color. I'm not sure exactly how many colors, but it's far more than 6. In particular, at the division where my ticks and labels are, the color spans the tick.
>
>>
>
>> Here's my snippet:
>
>>
>
>> cgloadct,0
>
>> cgloadct,2,bottom=1,ncolors=6,/rev
>
>> nc=6
>
>> levels = indgen(7)*5
>
>> lab=string(levels,format='(i3)')
>
>> lab=strcompress(lab,/remove_all)
>
>> cgcolorbar, ticknames=lab, charsize=4, charthick=2,/discrete, $
>
>> bottom=1, ncolors=nc, annotatecolor=cgcolor('black'), font=1, $
>
>> /right, /vert, title = 'levels', pos=[0.87,0.10,0.89,0.90]
>
>>
>
>> As I said, if I plot this in a window using the X device, it's fine and as I expect, but using the postscript device gives far more than 6 levels, with graduating color particularly visible around the tickmarks. You'll note that I load the second colorbar into the first 6 color indices only, but the postscript still results in graduating colors over those 6 colors.
>
>>
>
>> I'm using IDL 8.1 on OS 10.6.5, but have also tried this on IDL 7.0 and IDL 8.2.1 and the same thing happens every time.
>
>
>
> This is not a problem with the PostScript file, nor with
>
> cgColorbar. Rather, it is a problem with the PostScript
>
> viewer on the Mac. It just doesn't want to deal with
>
> less than 256 colors, apparently, so it makes them up
>
> if they aren't there.
>
>
>
> If you made a PNG file out of this PostScript file, you
>
> would see only six colors. And if you use a different
>
> PostScript viewer (say GhostView), you will see only
>
> six colors.
>
>
>
> I don't own a Mac, so I don't know if it is possible to
>
> get the Mac PostScript viewer to see what is actually
>
> there. Does anyone else know?
>
>
>
> Cheers,
>
>
>
> David
>
>
>
>
>
>
>
> --
>
> David Fanning, Ph.D.
>
> Fanning Software Consulting, Inc.
>
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
> Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: cgcolorbar problem in postscript [message #81970 is a reply to message #81968] Mon, 05 November 2012 04:42 Go to previous messageGo to next message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Ailie writes:

> I'm trying to make a discrete colorbar for an image and plotting straight to postscript. But cgcolorbar.pro is giving some unexpected behaviour.
>
> Basically, I'm trying to plot a discrete colorbar (using the DISCRETE keyword) with 6 colors in postscript. If I plot in using the X device, it behaves as I expect, producing a colorbar with six, distinct divisions, each division filled with a solid block of color.
>
> But when I plot in postscript, my resulting colorbar most definitely has more than 6 colors and instead appears to have graduating color. I'm not sure exactly how many colors, but it's far more than 6. In particular, at the division where my ticks and labels are, the color spans the tick.
>
> Here's my snippet:
>
> cgloadct,0
> cgloadct,2,bottom=1,ncolors=6,/rev
> nc=6
> levels = indgen(7)*5
> lab=string(levels,format='(i3)')
> lab=strcompress(lab,/remove_all)
> cgcolorbar, ticknames=lab, charsize=4, charthick=2,/discrete, $
> bottom=1, ncolors=nc, annotatecolor=cgcolor('black'), font=1, $
> /right, /vert, title = 'levels', pos=[0.87,0.10,0.89,0.90]
>
> As I said, if I plot this in a window using the X device, it's fine and as I expect, but using the postscript device gives far more than 6 levels, with graduating color particularly visible around the tickmarks. You'll note that I load the second colorbar into the first 6 color indices only, but the postscript still results in graduating colors over those 6 colors.
>
> I'm using IDL 8.1 on OS 10.6.5, but have also tried this on IDL 7.0 and IDL 8.2.1 and the same thing happens every time.

This is not a problem with the PostScript file, nor with
cgColorbar. Rather, it is a problem with the PostScript
viewer on the Mac. It just doesn't want to deal with
less than 256 colors, apparently, so it makes them up
if they aren't there.

If you made a PNG file out of this PostScript file, you
would see only six colors. And if you use a different
PostScript viewer (say GhostView), you will see only
six colors.

I don't own a Mac, so I don't know if it is possible to
get the Mac PostScript viewer to see what is actually
there. Does anyone else know?

Cheers,

David



--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thue. ("Perhaps thos speakest truth.")
Re: cgcolorbar problem in postscript [message #84707 is a reply to message #81968] Wed, 07 November 2012 08:30 Go to previous message
Phillip M. Bitzer is currently offline  Phillip M. Bitzer
Messages: 7
Registered: September 2012
Junior Member
Like David said, this is not a problem with the file or cgColorbar, but
I don't think this is a "problem" exactly with Preview either - it seems
to be an issue with aliasing. Consider the program below, which is
similar to yours (note I don't load in a color bar, rather I specify the
RGB palette). After producing the eps file, open it in Preview. You'll
probably see the graduated colors, which I think is what you are reporting.

If you go to Preferences->PDF, and toggle the Check box for "Smooth text
and line art", then you will see your discrete color bar reappear. The
text won't look as nice, however. This is an issue with the default
aliasing used by Preview - smoothing introduces the graduated colors you
see.

For reference, here's what I see:
https://www.dropbox.com/s/rvax832ot0t8l2b/colorbar_nosmooth. png

https://www.dropbox.com/s/2b2k8jj1taifpk0/colorbar_smooth.pn g

PRO pmbtest, Do_Ps = do_ps

colors = [ 'hot pink', 'indian red', 'dark green', 'green', $
'sky blue', 'cadet blue', 'grey', 'blue', 'purple', 'red']

n_color = N_ELEMENTS(colors)

do_ps = KEYWORD_SET(do_ps)
IF do_ps THEN BEGIN
PS_START, filename='test.eps', /ENCAP, /NOMATCH, $
XSIZE=6, YSIZE=2, /INCHES
ENDIF ELSE cgERASE, 'white'

rgb = cgCOLOR(colors, /TRIPLE)

;display the colorbar
cgCOLORBAR, /DISCRETE, NCOLORS=n_color, PALETTE = rgb, POSITION=[0.1,
0.2, 0.9, 0.9]

IF do_ps THEN PS_END

END
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: NDVI
Next Topic: Re: Finding pixel values of GeoTIFF image based on lat/lon (ENVI and IDL give different results).

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

Current Time: Wed Oct 08 13:48:41 PDT 2025

Total time taken to generate the page: 0.00490 seconds