;+ ; ; @file_comments ; The purpose of this routine is to add a color bar to the current ; graphics window. ; ; @categories ; Graphics ; ; @keyword BOTTOM {default=0B} ; The lowest color index of the colors to be loaded in the bar. ; ; @keyword CB_CHARSIZE {default=1.0} ; The character size of the color bar annotations. ; ; @keyword CB_CHARTHICK {default=1.0} ; The character thick of the color bar annotations. ; ; @keyword CB_COLOR {default=ncolors - 1 + bottom} ; The color index of the bar outline and characters. ; ; @keyword CB_LOG ; to get logarithmic scale for the colorbar ; ; @keyword CB_TITLE {default=''} ; This is title for the color bar. ; ; @keyword DISCRETE ; Vector which contain color's indexes to trace in a color bar. Therefore ; we obtain a discrete colorbar which contains only the specified colors ; in the order they appear in the vector ; ; @keyword DIVISIONS {default=2} ; The number of divisions to divide the bar into. ; There will be (divisions + 1) annotations. ; ; @keyword FORMAT {default='(F6.2)'} ; The format of the bar annotations. ; ; @keyword CB_LABEL {type=vector} ; A vector to specify sticks values of the color bar. It allows, ; when we use DISCRETE, to have colors that don't increase by ; increments in a regular way. ; ; @keyword MAX {default=NCOLORS - 1} ; The maximum data value for the bar annotation. ; ; @keyword MIN {default=0} ; The minimum data value for the bar annotation. ; ; @keyword NCOLORS {default=!D.N_COLORS} ; This is the number of colors in the color bar. ; ; @keyword NOTITLE ; Force to don't write title even if CB_TITLE is declared. ; ; @keyword POSITION {default=see bellow} ; A four-element array of normalized coordinates in the same ; form as the POSITION keyword on a plot. Default is ; [0.88, 0.15, 0.95, 0.95] for a vertical bar and ; [0.15, 0.88, 0.95, 0.95] for a horizontal bar. ; ; @keyword PSCOLOR ; This keyword is only applied if the output is being sent to ; a Postscript file. It indicates that the Postscript device ; is configured for color output. If this keyword is set, then ; the annotation is drawn in the color specified by the COLOR ; keyword. If the keyword is not set, the annotation is drawn ; in the color specified by the !P.COLOR system variable ; (usually this will be the color black). In general, this ; gives better looking output on non-color or gray-scale ; printers. If you are not specifically setting the annotation ; color (with the COLOR keyword), it will probably ; be better NOT to set this keyword either, even if you ; are outputting to a color Postscript printer. ; ; @keyword RIGHT ; This puts the labels on the right-hand side of a vertical ; color bar. It applies only to vertical color bars. ; ; @keyword TOP ; This puts the labels on top of the bar rather than under it. ; The keyword only applies if a horizontal color bar is rendered. ; ; @keyword VERTICAL {default=0 -> horizontal color bar} ; Setting this keyword give a vertical color bar. ; ; @keyword _EXTRA ; pass any keyword to colorbar ; ; @restrictions ; The number of colors available on the display device (not the ; Postscript device) is used unless the NCOLORS keyword is used. ; ; @examples ; To display a horizontal color bar above a contour plot, type: ; ; IDL> LOADCT, 5, NCOLORS=100 ; IDL> CONTOUR, DIST(31,41), POSITION=[0.15, 0.15, 0.95, 0.75], $ ; IDL> C_COLORS=INDGEN(25)*4, NLEVELS=25 ; IDL> COLORBAR, NCOLORS=100 ; ; @history ; Written by: David Fanning, 10 JUNE 96. ; 10/27/96: Added the ability to send output to PostScript. DWF ; 11/04/96: Substantially rewritten to go to screen or PostScript ; file without having to know much about the PostScript device ; or even what the current graphics device is. DWF ; 01/27/97: Added the RIGHT and TOP keywords. Also modified the ; way the TITLE keyword works. DWF ; 07/15/97: Fixed a problem some machines have with plots that have ; no valid data range in them. DWF ; 03/03/98: Add DISCRETE keyword, sebastien masson (smasson\@lodyc.jussieu.fr) ; ; @version ; $Id$ ; ;- PRO colorbar, BOTTOM=bottom, CB_CHARSIZE=cb_charsize, CB_CHARTHICK=cb_charthick $ , CB_COLOR=cb_color, DIVISIONS=divisions, DISCRETE=discrete $ , CB_LABEL = cb_label, FORMAT=format, POSITION=position $ , MAX = max, MIN = min, NCOLORS = ncolors, PSCOLOR=pscolor $ , CB_TITLE = cb_title, VERTICAL = vertical, TOP = top, RIGHT = right $ , CB_LOG = CB_log, NOTITLE = notitle, _EXTRA = ex ; compile_opt idl2, strictarrsubs ; ; Is the PostScript device selected? postScriptDevice = (!D.NAME EQ 'PS') ; Check and define keywords. IF N_ELEMENTS(ncolors) EQ 0 THEN BEGIN ; Most display devices to not use the 256 colors available to ; the PostScript device. This presents a problem when writing ; general-purpose programs that can be output to the display or ; to the PostScript device. This problem is especially bothersome ; if you don't specify the number of colors you are using in the ; program. One way to work around this problem is to make the ; default number of colors the same for the display device and for ; the PostScript device. Then, the colors you see in PostScript are ; identical to the colors you see on your display. Here is one way to ; do it. IF postScriptDevice THEN BEGIN oldDevice = !D.NAME ; What kind of computer are we using? SET_PLOT to appropriate ; display device. thisOS = !VERSION.OS_FAMILY thisOS = STRMID(thisOS, 0, 3) thisOS = STRUPCASE(thisOS) CASE thisOS of 'MAC': SET_PLOT, thisOS 'WIN': SET_PLOT, thisOS ELSE: SET_PLOT, 'X' ENDCASE !p.BACKGROUND=(!d.n_colors-1) < 255 !p.color=0 if !d.n_colors gt 256 then !p.background='ffffff'x ; Open a window (to make sure !D.N_COLORS is accurate). WINDOW, /FREE, /PIXMAP, XSIZE=10, YSIZE=10 WDELETE, !D.WINDOW ; Here is how many colors we should use. ncolors = !D.N_COLORS SET_PLOT, oldDevice IF oldDevice EQ 'X' OR oldDevice EQ 'MAC' OR oldDevice EQ 'WIN' then BEGIN !p.BACKGROUND=(!d.n_colors-1) < 255 !p.color=0 if !d.n_colors gt 256 then !p.background='ffffff'x ENDIF ENDIF ELSE ncolors = !D.N_COLORS ENDIF IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0B IF N_ELEMENTS(cb_charsize) EQ 0 THEN cb_charsize = 1.0 IF N_ELEMENTS(cb_charthick) EQ 0 THEN cb_charthick = 1.0 IF N_ELEMENTS(format) EQ 0 THEN format = '(F6.2)' IF N_ELEMENTS(cb_color) EQ 0 THEN cb_color = ncolors - 1 + bottom IF N_ELEMENTS(min) EQ 0 THEN min = 0.0 IF N_ELEMENTS(max) EQ 0 THEN max = FLOAT(ncolors) - 1 IF N_ELEMENTS(divisions) EQ 0 THEN divisions = 2 IF N_ELEMENTS(cb_title) EQ 0 THEN cb_title = '' IF N_ELEMENTS(notitle) EQ 1 THEN cb_title = '' pscolor = KEYWORD_SET(pscolor) IF KEYWORD_SET(vertical) THEN BEGIN IF KEYWORD_SET(discrete) THEN begin facteur=256/n_elements(discrete) discrete=reform(replicate(1,facteur) # discrete,facteur*n_elements(discrete), /overwrite) bar = REPLICATE(1B,10) # discrete endif else bar = REPLICATE(1B,10) # BINDGEN(256) IF N_ELEMENTS(position) EQ 0 THEN position = [0.88, 0.15, 0.95, 0.95] ENDIF ELSE BEGIN IF KEYWORD_SET(discrete) THEN begin facteur=256/n_elements(discrete) discrete=reform(replicate(1,facteur) # discrete,facteur*n_elements(discrete), /overwrite) bar = discrete # REPLICATE(1B,10) endif else bar = BINDGEN(256) # REPLICATE(1B, 10) IF N_ELEMENTS(position) EQ 0 THEN position = [0.15, 0.88, 0.95, 0.95] ENDELSE ; Scale the color bar. IF NOT KEYWORD_SET(discrete) THEN $ bar = BYTSCL(bar, TOP=ncolors-1) + bottom ; Get starting locations in DEVICE coordinates. xstart = position[0] * !D.X_VSIZE ystart = position[1] * !D.Y_VSIZE ; Get the size of the bar in DEVICE coordinates. xsize = (position[2] - position[0]) * !D.X_VSIZE ysize = (position[3] - position[1]) * !D.Y_VSIZE ; For PostScript output only, draw the annotation in !P.COLOR ; unless "pscolor" is set. This makes better output on grayscale ; printers. IF postScriptDevice AND (pscolor NE 1) THEN BEGIN oldcolor = cb_color cb_color = !P.COLOR ENDIF ; Display the color bar in the window. Sizing is ; different for PostScript and regular display. IF postScriptDevice THEN BEGIN TV, bar, xstart, ystart, XSIZE=xsize, YSIZE=ysize ENDIF ELSE BEGIN IF CEIL(xsize) LT 0 OR CEIL(ysize) LT 0 THEN return bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP) TV, bar, xstart, ystart ENDELSE ; Annotate the color bar. if keyword_set(cb_label) then begin divisions = n_elements(cb_label)-1 for i = 0,divisions DO cb_label = string(cb_label, FORMAT = format) format = '' ENDIF ELSE cb_label = '' IF KEYWORD_SET(vertical) THEN BEGIN IF KEYWORD_SET(right) THEN BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize, CHARTHICK=cb_charthick $ , /NOERASE, $ YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ YRANGE=[min, max], YTITLE=cb_title AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT=format, YTICKS=divisions, $ YTICKLEN=0.1, YSTYLE=1, COLOR=cb_color, CHARTHICK=cb_charthick $ , CHARSIZE=cb_charsize, xtickname = cb_label, ylog = cb_log ENDIF ELSE BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ , CHARTHICK=cb_charthick, /NOERASE, $ YTICKFORMAT=format, XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ YRANGE=[min, max], xtickname = cb_label AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT='(A1)', YTICKS=divisions, $ YTICKLEN=0.1, YTITLE=cb_title, YSTYLE=1, COLOR=cb_color $ , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, ylog = cb_log ENDELSE ENDIF ELSE BEGIN IF KEYWORD_SET(top) THEN BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ YTICKS=1, XSTYLE=9, YSTYLE=1, $ POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ , CHARTHICK=cb_charthick, /NOERASE, $ YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', XTICKLEN=0.1, $ XRANGE=[min, max], XTITLE=cb_title AXIS, XTICKS=divisions, XSTYLE=1, COLOR=cb_color $ , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, $ XTICKFORMAT=format, XTICKLEN=0.1, XRANGE=[min, max], XAXIS=1, xtickname = cb_label, xlog = cb_log ENDIF ELSE BEGIN PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ YTICKS=1, XSTYLE=1, YSTYLE=1, $ POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ , CHARTHICK=cb_charthick, /NOERASE, $ YTICKFORMAT='(A1)', XTICKFORMAT=format, XTICKLEN=0.1, $ XRANGE=[min, max], TITLE=cb_title, xtickname = cb_label, xlog = cb_log ENDELSE ENDELSE ; Restore color variable if changed for PostScript. IF postScriptDevice AND (pscolor NE 1) THEN cb_color = oldcolor return END