Here is one possible way to display an image and produce a color bar legend. It
was written for PV-WAVE.
Ron
************************************************************ *************************
; PROCEDURE for COLOR output from TVSCL with COLOR BAR
;
PRO tvsclbar, array, white=white,txtcol=txtcol,txtsiz=txtsiz,nobar=nobar,min=min, max=max
ON_ERROR, 2 ;Return to calling program if error
array_size = SIZE(array)
xdim = array_size(1)
ydim = array_size(2)
array_max = MAX(array,MIN=array_min) ;Determine data minimum and maximum values
IF N_ELEMENTS(min) THEN array_min = min ;Override minimum if set set as an argument
IF N_ELEMENTS(max) THEN array_max = max ;Override maximum if set set as an argument
display = BYTSCL(array,MIN=array_min,MAX=array_max,TOP=!D.N_COLORS)
barwidth = 16
barheight = 0.75 * ydim
background_color = !P.BACKGROUND ; Current background color
IF N_ELEMENTS(white) THEN BEGIN ; Replace values <= white with maximum color value
IF NOT N_ELEMENTS(min) THEN array_min = MIN(array>white) ; Minimum value in matrix >= white
display = BYTSCL(array>white,MIN=array_min,MAX=array_max,TOP=!D.N_COLORS) ; Rescale
display(WHERE(array LE white)) = !D.N_COLORS ; Reset all entries <= white
background_color = !D.N_COLORS ; Set the background color so it will be "white"
ENDIF
;
; Adjust text color and size. Necessary when color matches background or text is wrong size.
;
textcolor = !D.N_COLORS
IF N_ELEMENTS(txtcol) THEN textcolor = BYTE(txtcol)
textsize = 1.0
IF N_ELEMENTS(txtsiz) THEN textsize = txtsiz ; Change textsize if desired
;
; Erase the display window, set desired background color, and display the image
;
ERASE, background_color ;erase window, setting appropriate background color
TV,display
;
; If a color bar is desired (default) generate an array for the colors and draw it with
; intensity annotations and an outlining box
;
IF NOT N_ELEMENTS(nobar) THEN BEGIN
;
; Create color bar. The color_scale is initially 1 pixel wide
;
color_bar = MAKE_ARRAY(1,!D.N_COLORS,/byte,/index) ;Make a vector to use as a color bar
color_bar2 = CONGRID(color_bar,barwidth,0.75*ydim) ;Make a bigger vector for the display
color_scale = array_min + (MAKE_ARRAY(5,/float,/index) * (array_max-array_min)/4.)
TV,color_bar2,xdim,ydim/8,/DEVICE ;Draw the color bar
FOR i=0,4 DO BEGIN ; Label the color scale
XYOUTS,xdim+barwidth+4,FIX(ydim/16*(2.0+3.0*i)), $
STRCOMPRESS(STRING(color_scale(i),FORMAT='(G8.2)'),/REMOVE_A LL), $
/DEVICE,SIZE=textsize,COLOR=textcolor
ENDFOR
; Draw box around the color scale
PLOTS,[[xdim,ydim/8],[xdim,ydim/8+barheight],[xdim+barwidth, ydim/8+barheight], $
[xdim+barwidth,ydim/8],[xdim,ydim/8]],COLOR=textcolor,/DEVIC E
ENDIF
END
|