Jeff Haferman <haferman@audry.gsfc.nasa.gov> writes:
> I've got datapoints (x,y,z) and I'm using IDL
> to produce a contour plot of z at locations (x,y).
>
> This is easy enough to do with IDL, but I don't see
> in the manuals (we have the Version 3.6 manuals) how
> I can add a colorbar legend to the contour plots.
Suppose you wanted to add a horizontal color bar over the top
of your contour plot. Here is one way to do it.
First, load some colors. Let's suppose you want 200 colors.
LOADCT, 5, NCOLORS=200
ncolors = 200
Next, leave some space at the top of your contour plot
for the color bar with the POSITION keyword. Like this:
CONTOUR, DIST(31, 41), NLEVELS=25, $
C_COLORS=INDGEN(25)*8, POSITON=[0.15, 0.15, 0.95, 0.8]
Now, suppose you want the color bar to be the length of the
contour plot, and positioned above it. You might specify its
location like this:
loc = [0.15, 0.80, 0.95, 0.90]
I like to place my color bars in NORMAL coordinates, so that they
go into any sized window. (Most of my graphics windows are
resizeable these days.)
Now create a color bar. (For a vertical bar exchange the two
expressions on either side of the matrix multiplier.)
bar = BINDGEN(256) # REPLICATE(1B, 10)
Size the color bar for the current graphics window.
xsize = (loc(2) - loc(0)) * !D.X_VSIZE
ysize = (loc(3) - loc(1)) * !D.Y_VSIZE
bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP)
Scale the color bar to the number of colors you are using.
bar = BYTSCL(bar, TOP=ncolors-1)
Display the color bar in the window.
TV, bar, loc(0), loc(1), /NORMAL
Draw a box around the bar.
PLOTS, [loc(0), loc(0), loc(2), loc(2), loc(0)], $
[loc(1), loc(3), loc(3), loc(1), loc(1)], /NORMAL
Now, you can add annotations to the bar as needed. Many people
use XYOUTS. I like to use the PLOT command to label the
color bar because this gives me tick marks, nice labels, etc.
It's up to you.
You can download a fancier version of this from my
anonymous ftp site. Use anonymous ftp to the machine
ftp.frii.com. Look in /pub/dfanning/outgoing/idl_examples
for the file colorbar.pro.
Note that this is only *one* way to produce color bars in IDL.
You will probably discover other code and ways if you poke
around at the various IDL sites.
Hope this gives you some ideas.
Cheers!
David
--
David Fanning, Ph.D.
Phone: 970-221-0438
Fax: 970-221-4728
E-Mail: davidf@fortnet.org
|