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

Home » Public Forums » archive » adding a colorbar legend to a contour plot?
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
adding a colorbar legend to a contour plot? [message #7154] Thu, 10 October 1996 00:00 Go to next message
haferman is currently offline  haferman
Messages: 9
Registered: October 1996
Junior Member
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 legen to the contour plots.

I'm new to this newsgroup; is there a FAQ, or could
somone mail me a small snippet of code to perform this
task?

Thanks,

Jeff
Re: adding a colorbar legend to a contour plot? [message #7238 is a reply to message #7154] Mon, 14 October 1996 00:00 Go to previous message
G�nter Kargl is currently offline  G�nter Kargl
Messages: 3
Registered: October 1996
Junior Member
Jeff Haferman wrote:
>
> 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 legen to the contour plots.
>
> I'm new to this newsgroup; is there a FAQ, or could
> somone mail me a small snippet of code to perform this
> task?
>
> Thanks,
>
> Jeff

Hi Jeff,

I have the same problem of making a color-coded temperature map of a
2-dimmensional area. For this purpose I have writen a routine making a
contour plot overlaying a color image ov the data (TVSCL). On the levt
side a color bar is plotted. If you like you could have a copy of this.
It is pretty much independend and works even in a !p.multi environment.
Besides you could have four x,y axes, postscript plots,..... But simply
looking at the code will make you understand the way of producing color
bars. Unfortunately it is not thoroughly documented, but you will
understand.

Gunter
--
Kargl G�nter Mailto: kargl@limar1.mpae.gwdg.de
Max-Planck Inst, f. Aeronomie Phone: ++49 5556 979 234
Max-Planck Str. 2 Fax:: ++49 5556 979 240
D- 37191 Katlenburg-Lindau
Germany
Re: adding a colorbar legend to a contour plot? [message #7249 is a reply to message #7154] Thu, 10 October 1996 00:00 Go to previous message
davidf is currently offline  davidf
Messages: 2866
Registered: September 1996
Senior Member
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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: IDL Editor question
Next Topic: readu/writeu oddity in xdr files

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

Current Time: Wed Oct 08 15:39:43 PDT 2025

Total time taken to generate the page: 0.00773 seconds