MAKING A COLORBAR/IMAGE COMBO May 3, 2006

Carl Heiles

Here is a quick way to make a colorbar/image combination. Colorbars are important: the colorbar is like labeling your intensity axis. This is just as important as labeling your other axes!

You must use our local versions of colorbar and display, which (for ugastro) are locataed in ~ay121/idl/gen. To check this: the local display has no documentation whatsoever; and for colorbar, When you type doc_library, colorbar in IDL, one of the top few lines says

     **** WORK IN PROGRESS;; DOCUMENTATION MAY WELL BE WRONG!!!!!!!!

But it really does work!

Our attached figures provide two examples of colorbar-calibrated images, one with a vertical and one a horizontal colorbar. Getting these positioned and sized is a bit tricky and you can do it yourself—or you can use our routine cb_setup. You invoke it with

    cb_setup, xim, yim, posplot, posbar, w, cbx, sep, vertical=vertical

If you like the default setup on our figures, you don’t need to specify any inputs; alternatively, you can specify w, cbx, sep if you wish. If you don’t specify them they are outputs. The parameters are:

OUTPUTS:
       xim is the horizontal size of image in normalized coordinates
       yim is the vertical size of image in normalized coordinates
       posplot[4] is the image position corners in normralized coordinates
       posbar[4] is the colorbar position corners in normalized coords
       w is the width of the frame (white blank space)
       cbx is the short dimension of the colorbar in normalized coordinates
       sep is the separation between the  colorbar and image in normalized coords
if w, cbx, and sep are not specified, their defaults are (0.1, 0.1, 0.04)

We now present the IDL commands required to make these colorbar/image combinations. We assume that: your image is size xsz by ysz pixels; you want to display your image in greyscale; the data values in your image range from 0 to 2 (corresponding to the byte range of 0 to 255 in the image); and your image-axis and colorbar-axis titles are as shown on the figures. Also, setting ps gives you a postscript output, not setting it gives you X-window output. Use the following IDL commands:

;IMG IS THE NAME OF THE IMAGE...
xsz= (size(img))[1]  ;NR OF X PIXELS IN IMAGE
ysz= (size(img))[2]  ;NR OF Y PIXELS IN IMAGE
vertical=1     ;GIVES VERTICAL COLORBAR
cb_setup, xim, yim, posplot, posbar, w, cbx, sep, vertical=vertical
        ;CALCULAATES THE LOCATION AND SIZE OF THE DISPLAY
if ps eq 1 then psopen, filename, /times, /bold, /isolatin1, /color ;OPENS PS FILE
if ps eq 0 then window, 9, xs= xsz/xim, ys= ysz/yim ;OPENS WINDOW
if ps eq 0 then device, decomposed=0 ;ASSURES YOU ARE USING A COLORTABLE
loadct, 0  ;*** ASSURES GREYSCALE
colr= [ [r_orig], [g_orig], [b_orig] ]  ;DEFINES COLR ARRAY USING GREYSCALE
tv, img, w, w, /norm, xsize=xim, ysize=yim ;WRITES THE IMAGE TO THE DISPLAY
setcolors, /system_variables; ASSURES YOUR COLORTABLES ARE OK FOR GRAPHICS
loadct,0 ;ASSURES BLACK/WHITE FOR LABELLING
plot, [0], [0], pos= posplot, $
            /xsty, /ysty, /norm, /noerase, /nodata, $
            xtit= 'X', ytit= 'Y', font=ps-1, back=!black
        ;ADDS PLOTTING AXES TO THE IMAGE
colorbar, pos= posbar, crange= [0.,2.], rgb=colr, $
            vertical= vertical, $
            xtitle= 'XT', ytitle= 'YT', font=ps-1;;; , xticks=4, yticks=4
        ;WRITE THE COLORBAR TO THE DISPLAY; USE XTICKS, YTICKS IF NEEDED
loadct,0 ;*** RESETS THINGS AFTER COLORBAR
if ps eq 1 then psclose ;CLOSES PS FILE

If you want to use a different IDL colortable for the image and colorbar, specify its number in the loadct statements annotated with *** above. The above statements are also given in the documentation of cb_setup.

– 3 –

Fig. 1.— Horizontal colorbar

– 4 –

Fig. 2.— Vertical colorbar