[2] | 1 | ;+ |
---|
| 2 | ; |
---|
[136] | 3 | ; @file_comments |
---|
[133] | 4 | ; The purpose of this routine is to add a color bar to the current |
---|
| 5 | ; graphics window. |
---|
[2] | 6 | ; |
---|
[231] | 7 | ; @categories |
---|
[318] | 8 | ; Graphics |
---|
[2] | 9 | ; |
---|
[137] | 10 | ; @keyword BOTTOM {default=0B} |
---|
[136] | 11 | ; The lowest color index of the colors to be loaded in the bar. |
---|
[2] | 12 | ; |
---|
[136] | 13 | ; @keyword CB_CHARSIZE {default=1.0} |
---|
| 14 | ; The character size of the color bar annotations. |
---|
[2] | 15 | ; |
---|
[136] | 16 | ; @keyword CB_CHARTHICK {default=1.0} |
---|
| 17 | ; The character thick of the color bar annotations. |
---|
[2] | 18 | ; |
---|
[136] | 19 | ; @keyword CB_COLOR {default=ncolors - 1 + bottom} |
---|
| 20 | ; The color index of the bar outline and characters. |
---|
[2] | 21 | ; |
---|
[136] | 22 | ; @keyword CB_LOG |
---|
| 23 | ; to get logarithmic scale for the colorbar |
---|
[19] | 24 | ; |
---|
[137] | 25 | ; @keyword CB_TITLE {default=''} |
---|
| 26 | ; This is title for the color bar. |
---|
[2] | 27 | ; |
---|
[231] | 28 | ; @keyword DISCRETE |
---|
[136] | 29 | ; Vector which contain color's indexes to trace in a color bar. Therefore |
---|
[231] | 30 | ; we obtain a discrete colorbar which contains only the specified colors |
---|
[137] | 31 | ; in the order they appear in the vector |
---|
[2] | 32 | ; |
---|
[136] | 33 | ; @keyword DIVISIONS {default=2} |
---|
| 34 | ; The number of divisions to divide the bar into. |
---|
| 35 | ; There will be (divisions + 1) annotations. |
---|
[2] | 36 | ; |
---|
[136] | 37 | ; @keyword FORMAT {default='(F6.2)'} |
---|
| 38 | ; The format of the bar annotations. |
---|
[2] | 39 | ; |
---|
[163] | 40 | ; @keyword CB_LABEL {type=vector} |
---|
| 41 | ; A vector to specify sticks values of the color bar. It allows, |
---|
[137] | 42 | ; when we use DISCRETE, to have colors that don't increase by |
---|
| 43 | ; increments in a regular way. |
---|
[2] | 44 | ; |
---|
[136] | 45 | ; @keyword MAX {default=NCOLORS - 1} |
---|
| 46 | ; The maximum data value for the bar annotation. |
---|
[2] | 47 | ; |
---|
[136] | 48 | ; @keyword MIN {default=0} |
---|
| 49 | ; The minimum data value for the bar annotation. |
---|
[2] | 50 | ; |
---|
[137] | 51 | ; @keyword NCOLORS {default=!D.N_COLORS} |
---|
[136] | 52 | ; This is the number of colors in the color bar. |
---|
[2] | 53 | ; |
---|
[136] | 54 | ; @keyword NOTITLE |
---|
| 55 | ; Force to don't write title even if CB_TITLE is declared. |
---|
[2] | 56 | ; |
---|
[358] | 57 | ; @keyword POSITION {default=see below} |
---|
[136] | 58 | ; A four-element array of normalized coordinates in the same |
---|
| 59 | ; form as the POSITION keyword on a plot. Default is |
---|
| 60 | ; [0.88, 0.15, 0.95, 0.95] for a vertical bar and |
---|
| 61 | ; [0.15, 0.88, 0.95, 0.95] for a horizontal bar. |
---|
[2] | 62 | ; |
---|
[136] | 63 | ; @keyword PSCOLOR |
---|
| 64 | ; This keyword is only applied if the output is being sent to |
---|
| 65 | ; a Postscript file. It indicates that the Postscript device |
---|
| 66 | ; is configured for color output. If this keyword is set, then |
---|
| 67 | ; the annotation is drawn in the color specified by the COLOR |
---|
| 68 | ; keyword. If the keyword is not set, the annotation is drawn |
---|
| 69 | ; in the color specified by the !P.COLOR system variable |
---|
| 70 | ; (usually this will be the color black). In general, this |
---|
| 71 | ; gives better looking output on non-color or gray-scale |
---|
| 72 | ; printers. If you are not specifically setting the annotation |
---|
| 73 | ; color (with the COLOR keyword), it will probably |
---|
| 74 | ; be better NOT to set this keyword either, even if you |
---|
| 75 | ; are outputting to a color Postscript printer. |
---|
[2] | 76 | ; |
---|
[136] | 77 | ; @keyword RIGHT |
---|
| 78 | ; This puts the labels on the right-hand side of a vertical |
---|
| 79 | ; color bar. It applies only to vertical color bars. |
---|
[2] | 80 | ; |
---|
[136] | 81 | ; @keyword TOP |
---|
| 82 | ; This puts the labels on top of the bar rather than under it. |
---|
| 83 | ; The keyword only applies if a horizontal color bar is rendered. |
---|
[2] | 84 | ; |
---|
[137] | 85 | ; @keyword VERTICAL {default=0 -> horizontal color bar} |
---|
[136] | 86 | ; Setting this keyword give a vertical color bar. |
---|
[2] | 87 | ; |
---|
[155] | 88 | ; @keyword _EXTRA |
---|
| 89 | ; pass any keyword to colorbar |
---|
| 90 | ; |
---|
[136] | 91 | ; @restrictions |
---|
| 92 | ; The number of colors available on the display device (not the |
---|
| 93 | ; Postscript device) is used unless the NCOLORS keyword is used. |
---|
[2] | 94 | ; |
---|
[136] | 95 | ; @examples |
---|
| 96 | ; To display a horizontal color bar above a contour plot, type: |
---|
[2] | 97 | ; |
---|
[371] | 98 | ; IDL> LOADCT, 5, NCOLORS=100 |
---|
| 99 | ; IDL> CONTOUR, DIST(31,41), POSITION=[0.15, 0.15, 0.95, 0.75], $ |
---|
| 100 | ; IDL> C_COLORS=INDGEN(25)*4, NLEVELS=25 |
---|
| 101 | ; IDL> COLORBAR, NCOLORS=100 |
---|
[2] | 102 | ; |
---|
[231] | 103 | ; @history |
---|
[137] | 104 | ; Written by: David Fanning, 10 JUNE 96. |
---|
| 105 | ; 10/27/96: Added the ability to send output to PostScript. DWF |
---|
| 106 | ; 11/04/96: Substantially rewritten to go to screen or PostScript |
---|
| 107 | ; file without having to know much about the PostScript device |
---|
[2] | 108 | ; or even what the current graphics device is. DWF |
---|
[137] | 109 | ; 01/27/97: Added the RIGHT and TOP keywords. Also modified the |
---|
| 110 | ; way the TITLE keyword works. DWF |
---|
| 111 | ; 07/15/97: Fixed a problem some machines have with plots that have |
---|
| 112 | ; no valid data range in them. DWF |
---|
| 113 | ; 03/03/98: Add DISCRETE keyword, sebastien masson (smasson\@lodyc.jussieu.fr) |
---|
[133] | 114 | ; |
---|
[231] | 115 | ; @version |
---|
| 116 | ; $Id$ |
---|
[133] | 117 | ; |
---|
[2] | 118 | ;- |
---|
[327] | 119 | PRO colorbar, BOTTOM=bottom, CB_CHARSIZE=cb_charsize $ |
---|
| 120 | , CB_CHARTHICK=cb_charthick $ |
---|
| 121 | , CB_COLOR=cb_color, DIVISIONS=divisions, DISCRETE=discrete $ |
---|
| 122 | , CB_LABEL=cb_label, FORMAT=format, POSITION=position $ |
---|
| 123 | , MAX=max, MIN=min, NCOLORS=ncolors, PSCOLOR=pscolor $ |
---|
| 124 | , CB_TITLE=cb_title, VERTICAL=vertical, TOP=top, RIGHT=right $ |
---|
| 125 | , CB_LOG=CB_log, NOTITLE=notitle, _EXTRA=ex |
---|
[114] | 126 | ; |
---|
| 127 | compile_opt idl2, strictarrsubs |
---|
| 128 | ; |
---|
[137] | 129 | ; Is the PostScript device selected? |
---|
[2] | 130 | postScriptDevice = (!D.NAME EQ 'PS') |
---|
| 131 | |
---|
| 132 | ; Check and define keywords. |
---|
| 133 | |
---|
[479] | 134 | IF N_ELEMENTS(ncolors) EQ 0 THEN ncolors = !D.N_COLORS < 256 |
---|
[2] | 135 | IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0B |
---|
| 136 | IF N_ELEMENTS(cb_charsize) EQ 0 THEN cb_charsize = 1.0 |
---|
| 137 | IF N_ELEMENTS(cb_charthick) EQ 0 THEN cb_charthick = 1.0 |
---|
| 138 | IF N_ELEMENTS(format) EQ 0 THEN format = '(F6.2)' |
---|
| 139 | IF N_ELEMENTS(cb_color) EQ 0 THEN cb_color = ncolors - 1 + bottom |
---|
| 140 | IF N_ELEMENTS(min) EQ 0 THEN min = 0.0 |
---|
| 141 | IF N_ELEMENTS(max) EQ 0 THEN max = FLOAT(ncolors) - 1 |
---|
| 142 | IF N_ELEMENTS(divisions) EQ 0 THEN divisions = 2 |
---|
| 143 | IF N_ELEMENTS(cb_title) EQ 0 THEN cb_title = '' |
---|
| 144 | IF N_ELEMENTS(notitle) EQ 1 THEN cb_title = '' |
---|
| 145 | pscolor = KEYWORD_SET(pscolor) |
---|
| 146 | |
---|
| 147 | IF KEYWORD_SET(vertical) THEN BEGIN |
---|
[133] | 148 | IF KEYWORD_SET(discrete) THEN begin |
---|
| 149 | facteur=256/n_elements(discrete) |
---|
[136] | 150 | discrete=reform(replicate(1,facteur) # discrete,facteur*n_elements(discrete), /overwrite) |
---|
[133] | 151 | bar = REPLICATE(1B,10) # discrete |
---|
[2] | 152 | endif else bar = REPLICATE(1B,10) # BINDGEN(256) |
---|
| 153 | IF N_ELEMENTS(position) EQ 0 THEN position = [0.88, 0.15, 0.95, 0.95] |
---|
| 154 | ENDIF ELSE BEGIN |
---|
[133] | 155 | IF KEYWORD_SET(discrete) THEN begin |
---|
| 156 | facteur=256/n_elements(discrete) |
---|
[136] | 157 | discrete=reform(replicate(1,facteur) # discrete,facteur*n_elements(discrete), /overwrite) |
---|
[133] | 158 | bar = discrete # REPLICATE(1B,10) |
---|
[2] | 159 | endif else bar = BINDGEN(256) # REPLICATE(1B, 10) |
---|
| 160 | IF N_ELEMENTS(position) EQ 0 THEN position = [0.15, 0.88, 0.95, 0.95] |
---|
| 161 | ENDELSE |
---|
| 162 | |
---|
[137] | 163 | ; Scale the color bar. |
---|
[133] | 164 | IF NOT KEYWORD_SET(discrete) THEN $ |
---|
[2] | 165 | bar = BYTSCL(bar, TOP=ncolors-1) + bottom |
---|
| 166 | |
---|
[137] | 167 | ; Get starting locations in DEVICE coordinates. |
---|
[2] | 168 | |
---|
[114] | 169 | xstart = position[0] * !D.X_VSIZE |
---|
| 170 | ystart = position[1] * !D.Y_VSIZE |
---|
[2] | 171 | |
---|
[137] | 172 | ; Get the size of the bar in DEVICE coordinates. |
---|
[2] | 173 | |
---|
[114] | 174 | xsize = (position[2] - position[0]) * !D.X_VSIZE |
---|
| 175 | ysize = (position[3] - position[1]) * !D.Y_VSIZE |
---|
[2] | 176 | |
---|
[137] | 177 | ; For PostScript output only, draw the annotation in !P.COLOR |
---|
| 178 | ; unless "pscolor" is set. This makes better output on grayscale |
---|
| 179 | ; printers. |
---|
[2] | 180 | |
---|
| 181 | IF postScriptDevice AND (pscolor NE 1) THEN BEGIN |
---|
| 182 | oldcolor = cb_color |
---|
| 183 | cb_color = !P.COLOR |
---|
| 184 | ENDIF |
---|
| 185 | |
---|
[137] | 186 | ; Display the color bar in the window. Sizing is |
---|
| 187 | ; different for PostScript and regular display. |
---|
[2] | 188 | |
---|
| 189 | IF postScriptDevice THEN BEGIN |
---|
| 190 | |
---|
| 191 | TV, bar, xstart, ystart, XSIZE=xsize, YSIZE=ysize |
---|
| 192 | |
---|
| 193 | ENDIF ELSE BEGIN |
---|
| 194 | |
---|
[154] | 195 | IF CEIL(xsize) LT 0 OR CEIL(ysize) LT 0 THEN return |
---|
[2] | 196 | bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP) |
---|
| 197 | TV, bar, xstart, ystart |
---|
| 198 | |
---|
| 199 | ENDELSE |
---|
| 200 | |
---|
[137] | 201 | ; Annotate the color bar. |
---|
[2] | 202 | |
---|
| 203 | if keyword_set(cb_label) then begin |
---|
| 204 | divisions = n_elements(cb_label)-1 |
---|
| 205 | for i = 0,divisions DO cb_label = string(cb_label, FORMAT = format) |
---|
| 206 | format = '' |
---|
| 207 | ENDIF ELSE cb_label = '' |
---|
| 208 | |
---|
| 209 | IF KEYWORD_SET(vertical) THEN BEGIN |
---|
| 210 | |
---|
| 211 | IF KEYWORD_SET(right) THEN BEGIN |
---|
| 212 | |
---|
| 213 | PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ |
---|
| 214 | YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ |
---|
| 215 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize, CHARTHICK=cb_charthick $ |
---|
| 216 | , /NOERASE, $ |
---|
| 217 | YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ |
---|
| 218 | YRANGE=[min, max], YTITLE=cb_title |
---|
| 219 | |
---|
| 220 | AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT=format, YTICKS=divisions, $ |
---|
| 221 | YTICKLEN=0.1, YSTYLE=1, COLOR=cb_color, CHARTHICK=cb_charthick $ |
---|
[400] | 222 | , CHARSIZE=cb_charsize, ytickname = cb_label, ylog = cb_log |
---|
[2] | 223 | |
---|
| 224 | ENDIF ELSE BEGIN |
---|
| 225 | |
---|
| 226 | PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ |
---|
| 227 | YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ |
---|
| 228 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ |
---|
| 229 | , CHARTHICK=cb_charthick, /NOERASE, $ |
---|
| 230 | YTICKFORMAT=format, XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ |
---|
[400] | 231 | YRANGE=[min, max], ytickname = cb_label |
---|
[2] | 232 | |
---|
| 233 | AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT='(A1)', YTICKS=divisions, $ |
---|
| 234 | YTICKLEN=0.1, YTITLE=cb_title, YSTYLE=1, COLOR=cb_color $ |
---|
[19] | 235 | , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, ylog = cb_log |
---|
[2] | 236 | |
---|
| 237 | ENDELSE |
---|
| 238 | |
---|
| 239 | ENDIF ELSE BEGIN |
---|
| 240 | |
---|
| 241 | IF KEYWORD_SET(top) THEN BEGIN |
---|
| 242 | |
---|
| 243 | PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ |
---|
| 244 | YTICKS=1, XSTYLE=9, YSTYLE=1, $ |
---|
| 245 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ |
---|
| 246 | , CHARTHICK=cb_charthick, /NOERASE, $ |
---|
| 247 | YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', XTICKLEN=0.1, $ |
---|
| 248 | XRANGE=[min, max], XTITLE=cb_title |
---|
| 249 | |
---|
| 250 | AXIS, XTICKS=divisions, XSTYLE=1, COLOR=cb_color $ |
---|
| 251 | , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, $ |
---|
[19] | 252 | XTICKFORMAT=format, XTICKLEN=0.1, XRANGE=[min, max], XAXIS=1, xtickname = cb_label, xlog = cb_log |
---|
[2] | 253 | |
---|
| 254 | ENDIF ELSE BEGIN |
---|
| 255 | |
---|
| 256 | PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ |
---|
| 257 | YTICKS=1, XSTYLE=1, YSTYLE=1, $ |
---|
| 258 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ |
---|
| 259 | , CHARTHICK=cb_charthick, /NOERASE, $ |
---|
| 260 | YTICKFORMAT='(A1)', XTICKFORMAT=format, XTICKLEN=0.1, $ |
---|
[19] | 261 | XRANGE=[min, max], TITLE=cb_title, xtickname = cb_label, xlog = cb_log |
---|
[2] | 262 | |
---|
| 263 | ENDELSE |
---|
| 264 | |
---|
| 265 | ENDELSE |
---|
[137] | 266 | ; Restore color variable if changed for PostScript. |
---|
[2] | 267 | |
---|
| 268 | IF postScriptDevice AND (pscolor NE 1) THEN cb_color = oldcolor |
---|
| 269 | |
---|
| 270 | return |
---|
| 271 | END |
---|