Robin writes:
> 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.
> 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.
> 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!
> ; 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
> ; Calculate 100 levels for the contouring
> range = MAX(dns) - MIN(dns)
> levels = indgen(100) * (range/100)
Nice work here. :-)
> ; 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.")
|