Discussion:
Color problem with contours
(too old to reply)
robintw
2009-07-08 08:49:16 UTC
Permalink
Hi,

I'm trying to plot a circular (polar) contour plot using the map
plotting commands. I've attached my code below. I don't really
understand much about colours in IDL, but I found that it was being
displayed as white text on a black background. After a bit of playing
I found that adding the lines under the comment "Load colors into
colortable" made it display with a white background and black text.

However, this seems to add an extra line at the bottom of the
colortable, which means that very low values of my contours plot as
white (which makes it look as if they're not there, as the background
is white).

As I said, I don't really quite get IDL colors, even though I've read
various bits in books about them. I've tried playing with the "bottom"
keywords to various routines, but that doesn't really seem to help.
I've also tried playing with FSC_COLOR (which I'm using successfully
elsewhere in my program), but that just seemed to confuse things
entirely.

Ideally, what I'd like is to have a white background, with black text
and lines, and then with the colors for the contours plotting
correctly. I'm sure this must be possible, but I'm not sure how.

Any help would be much appreciated,

Robin
University of Southampton, UK

PRO MAP_PLOT_DATA, azimuths, zeniths, dns, title
; Set positions for drawing the plot and the colourbar
draw_position = [.10, .07, .80, .90]
cbar_position = [.85, .07, .88, .90]

; Set the map projection to orthographic, looking down from the
north pole
; The REVERSE=1 and the third numeric parameter (180) ensure that N,
E, S and W are at the appropriate locations
MAP_SET, /ORTHOGRAPHIC, 90, 0, 180, REVERSE=1, /ISOTROPIC,
title=title, position=draw_position, color=1

; Load colours into colortable
device, decomposed=0
loadct, 13
TVLCT, 0, 0, 0, 1 ; Drawing colour
TVLCT, 255, 255, 255, 0 ; Background colour

; Calculate 100 levels for the contouring
range = MAX(dns) - MIN(dns)
levels = indgen(100) * (range/100)

; Plot the contours from the irregular data
contour, dns, azimuths, zeniths, /irregular, /overplot,
levels=levels, /cell_fill, position=draw_position, color=1

; Plot the grid over the top of the data
map_grid, /grid, londel=45, latdel=20, color=1,
position=draw_position

colorbar, /vertical, /right, range=[min(dns), max(dns)],
position=cbar_position, title="Digital Number", color=1
END
David Fanning
2009-07-08 12:42:14 UTC
Permalink
Post by robintw
I'm trying to plot a circular (polar) contour plot using the map
plotting commands. I've attached my code below. I don't really
understand much about colours in IDL, but I found that it was being
displayed as white text on a black background. After a bit of playing
I found that adding the lines under the comment "Load colors into
colortable" made it display with a white background and black text.
However, this seems to add an extra line at the bottom of the
colortable, which means that very low values of my contours plot as
white (which makes it look as if they're not there, as the background
is white).
As I said, I don't really quite get IDL colors, even though I've read
various bits in books about them. I've tried playing with the "bottom"
keywords to various routines, but that doesn't really seem to help.
I've also tried playing with FSC_COLOR (which I'm using successfully
elsewhere in my program), but that just seemed to confuse things
entirely.
Sigh...

It is always so depressing to wake up and realize that your
life's work, to make IDL colors understandable to normal
people, is still unfinished after nearly twenty years of
work. It almost makes you want to go back to bed, to tell
you the truth.

OK, let me go fix a cup of coffee and I'll walk you through
it again.
Post by robintw
Ideally, what I'd like is to have a white background, with black text
and lines, and then with the colors for the contours plotting
correctly. I'm sure this must be possible, but I'm not sure how.
Here is a rule. Don't *ever* violate it or colors will
forever be incomprehensible to you. Do NOT use color
indices 0 or 255 for drawing colors. Ever. I mean it.
In your case, "drawing colors" means the colors you
want to use for your contour plot and black and white.
Post by robintw
PRO MAP_PLOT_DATA, azimuths, zeniths, dns, title
; Set positions for drawing the plot and the colourbar
draw_position = [.10, .07, .80, .90]
cbar_position = [.85, .07, .88, .90]
; Set the map projection to orthographic, looking down from the
north pole
; The REVERSE=1 and the third numeric parameter (180) ensure that N,
E, S and W are at the appropriate locations
MAP_SET, /ORTHOGRAPHIC, 90, 0, 180, REVERSE=1, /ISOTROPIC,
title=title, position=draw_position, color=1
In the command above you are using a color before you *load*
the color tables. That command might work once to give you
the right color, but it won't work twice. Here is another
rule: Load your colors BEFORE (and I usually mean JUST BEFORE)
you want to use them. Lord knows what else might be going
on in your programs (or others!) to muck with color tables.
Assume NOTHING!
Post by robintw
; Load colours into colortable
device, decomposed=0
loadct, 13
TVLCT, 0, 0, 0, 1 ; Drawing colour
TVLCT, 255, 255, 255, 0 ; Background colour
OK, it's clear you don't know what you are doing with colors
from this, since almost all rules are violated. :-)

You want 100 colors for contouring (I'm reading ahead a couple
of lines). Load those 100 colors somewhere other than in index
0 or 255. How about indices 1 to 100?

LoadCT, 13, NCOLORS=100, BOTTOM=1

You want black and white colors for drawing something. Put
those somewhere--anywhere--other than 0, 255, or 1-100.
Let's put them at indices 253 and 254, just for grins.

TVLCT, 0, 0, 0, 253 ; black
TVLCT, 255, 255, 255, 254 ; white

Now that you have your colors loaded, issue your MAP_SET
command. Alas, there is one problem. No BACKGROUND
keyword for MAP_SET. So if you want a white background
color, you have to fake it out. Also, you want to use
color indices (sigh...), so better put ourselves in
1970s color. Whoops! I mean "decomposed" color.

And, because you are going to want to do this in PostScript
as soon as I turn my back on you here, let's make sure
everything will work there, too.

Device, Decomposed=0
IF (!D.Flags AND 256) NE 0 THEN Erase, Color=254 ; white background
MAP_SET, /ORTHOGRAPHIC, 90, 0, 180, REVERSE=1, /ISOTROPIC, $
title=title, position=draw_position, color=253, /noerase
Post by robintw
; Calculate 100 levels for the contouring
range = MAX(dns) - MIN(dns)
levels = indgen(100) * (range/100)
Nice work here. :-)
Post by robintw
; Plot the contours from the irregular data
contour, dns, azimuths, zeniths, /irregular, /overplot,
levels=levels, /cell_fill, position=draw_position, color=1
; Plot the grid over the top of the data
map_grid, /grid, londel=45, latdel=20, color=1,
position=draw_position
colorbar, /vertical, /right, range=[min(dns), max(dns)],
position=cbar_position, title="Digital Number", color=1
Oh, dear. OK, there are black and white "drawing" colors,
and "contour" colors, stored at different places in the
color table. The Contour command needs to use both, as
does the Colorbar command. But you haven't even mentioned
the contour colors to either of those two commands.

Here is what we are going to do. "COLOR" is the drawing
color. "C_COLORS" are the contour colors. Do you see
that the contour colors go from 1 to 100?

contour, dns, azimuths, zeniths, /irregular, /overplot, $
levels=levels, /cell_fill, position=draw_position, $
COLOR=253, C_COLORS=Indgen(100)+1

Now the grid:

map_grid, /grid, londel=45, latdel=20, $
position=draw_position, COLOR=253

Now the color bar. Tell it where it should get its 100 colors!

colorbar, /vertical, /right, range=[min(dns), max(dns)], $
position=cbar_position, title="Digital Number", COLOR=253, $
NCOLORS=100, BOTTOM=1

Whew! Done. Much better. :-)

Cheers,

David

P.S. Twenty years of futile effort is available on my web page.
Most of these topics (well, all) have been discussed multiple
times. :-)
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
David Fanning
2009-07-08 12:50:09 UTC
Permalink
Post by David Fanning
Whoops! I mean "decomposed" color.
Whoops! I should have written "undecomposed"
color. Indexed color on modern computers makes
me cry so much it is hard to type. :-(

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Francis Burton
2009-07-08 14:24:29 UTC
Permalink
Post by David Fanning
Whoops! I should have written "undecomposed"
color. Indexed color on modern computers makes
me cry so much it is hard to type. :-(
Does that *still* happen?? Supplementary question: why?

Francis
David Fanning
2009-07-08 14:35:31 UTC
Permalink
Post by Francis Burton
Does that *still* happen?? Supplementary question: why?
God only knows. My theory is that people like to work
on geegaws that other people use once in a blue moon
more than they like to work on boring stuff that other
people use every day. But, I'm probably wrong. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
robintw
2009-07-09 13:33:07 UTC
Permalink
Hi David,

Thank you so much for your help. I've got it all working now, and I
actually understand what I'm doing (which is always helpful).

Thanks again,

Robin
David Fanning
2009-07-09 13:39:08 UTC
Permalink
Post by robintw
Thank you so much for your help. I've got it all working now, and I
actually understand what I'm doing (which is always helpful).
This kind of news gets me off to *such* a better start
in the morning! ;-)

Cheers,

David

P.S. Is it unseemly for an older gentleman to skip
to work?
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
Loading...