[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 | ; |
---|
[133] | 7 | ; @categories Graphics, Widgets. |
---|
[2] | 8 | ; |
---|
[136] | 9 | ; @keyword BOTTOM |
---|
| 10 | ; The lowest color index of the colors to be loaded in the bar. |
---|
[2] | 11 | ; |
---|
[136] | 12 | ; @keyword CB_CHARSIZE {default=1.0} |
---|
| 13 | ; The character size of the color bar annotations. |
---|
[2] | 14 | ; |
---|
[136] | 15 | ; @keyword CB_CHARTHICK {default=1.0} |
---|
| 16 | ; The character thick of the color bar annotations. |
---|
[2] | 17 | ; |
---|
[136] | 18 | ; @keyword CB_COLOR {default=ncolors - 1 + bottom} |
---|
| 19 | ; The color index of the bar outline and characters. |
---|
[2] | 20 | ; |
---|
[136] | 21 | ; @keyword CB_LOG |
---|
| 22 | ; to get logarithmic scale for the colorbar |
---|
[19] | 23 | ; |
---|
[136] | 24 | ; @keyword CB_TITLE |
---|
| 25 | ; This is title for the color bar. The default is to have no title. |
---|
[2] | 26 | ; |
---|
[136] | 27 | ; @keyword DISCRETE |
---|
| 28 | ; Vector which contain color's indexes to trace in a color bar. Therefore |
---|
| 29 | ; we obtain a discreet color bar which only contains specified colors in |
---|
| 30 | ; order where they appear in the vector |
---|
[2] | 31 | ; |
---|
[136] | 32 | ; @keyword DIVISIONS {default=2} |
---|
| 33 | ; The number of divisions to divide the bar into. |
---|
| 34 | ; There will be (divisions + 1) annotations. |
---|
[2] | 35 | ; |
---|
[136] | 36 | ; @keyword FORMAT {default='(F6.2)'} |
---|
| 37 | ; The format of the bar annotations. |
---|
[2] | 38 | ; |
---|
[136] | 39 | ; @keyword CB_LABEL |
---|
| 40 | ; It is a vector who specifies sticks's value attend in the color bar. |
---|
| 41 | ; It allowes, when we use DISCREET, to have colors which don't increase |
---|
| 42 | ; by increments in a regular way. |
---|
[2] | 43 | ; |
---|
[136] | 44 | ; @keyword MAX {default=NCOLORS - 1} |
---|
| 45 | ; The maximum data value for the bar annotation. |
---|
[2] | 46 | ; |
---|
[136] | 47 | ; @keyword MIN {default=0} |
---|
| 48 | ; The minimum data value for the bar annotation. |
---|
[2] | 49 | ; |
---|
[136] | 50 | ; @keyword NCOLORS |
---|
| 51 | ; This is the number of colors in the color bar. |
---|
[2] | 52 | ; |
---|
[136] | 53 | ; @keyword NOTITLE |
---|
| 54 | ; Force to don't write title even if CB_TITLE is declared. |
---|
[2] | 55 | ; |
---|
[136] | 56 | ; @keyword POSITION |
---|
| 57 | ; A four-element array of normalized coordinates in the same |
---|
| 58 | ; form as the POSITION keyword on a plot. Default is |
---|
| 59 | ; [0.88, 0.15, 0.95, 0.95] for a vertical bar and |
---|
| 60 | ; [0.15, 0.88, 0.95, 0.95] for a horizontal bar. |
---|
[2] | 61 | ; |
---|
[136] | 62 | ; @keyword PSCOLOR |
---|
| 63 | ; This keyword is only applied if the output is being sent to |
---|
| 64 | ; a Postscript file. It indicates that the Postscript device |
---|
| 65 | ; is configured for color output. If this keyword is set, then |
---|
| 66 | ; the annotation is drawn in the color specified by the COLOR |
---|
| 67 | ; keyword. If the keyword is not set, the annotation is drawn |
---|
| 68 | ; in the color specified by the !P.COLOR system variable |
---|
| 69 | ; (usually this will be the color black). In general, this |
---|
| 70 | ; gives better looking output on non-color or gray-scale |
---|
| 71 | ; printers. If you are not specifically setting the annotation |
---|
| 72 | ; color (with the COLOR keyword), it will probably |
---|
| 73 | ; be better NOT to set this keyword either, even if you |
---|
| 74 | ; are outputting to a color Postscript printer. |
---|
[2] | 75 | ; |
---|
[136] | 76 | ; @keyword RIGHT |
---|
| 77 | ; This puts the labels on the right-hand side of a vertical |
---|
| 78 | ; color bar. It applies only to vertical color bars. |
---|
[2] | 79 | ; |
---|
[136] | 80 | ; @keyword TOP |
---|
| 81 | ; This puts the labels on top of the bar rather than under it. |
---|
| 82 | ; The keyword only applies if a horizontal color bar is rendered. |
---|
[2] | 83 | ; |
---|
[136] | 84 | ; @keyword VERTICAL |
---|
| 85 | ; Setting this keyword give a vertical color bar. |
---|
| 86 | ; The default is a horizontal color bar. |
---|
[2] | 87 | ; |
---|
[136] | 88 | ; @restrictions |
---|
| 89 | ; Color bar is drawn in the current graphics window. |
---|
[2] | 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 | ; |
---|
[136] | 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 | ; |
---|
[133] | 103 | ; @history Written by: David Fanning, 10 JUNE 96. |
---|
[136] | 104 | ; 10/27/96: Added the ability to send output to Postscript. DWF |
---|
| 105 | ; 11/4/96: Substantially rewritten to go to screen or Postscript |
---|
| 106 | ; file without having to know much about the Postscript device |
---|
[2] | 107 | ; or even what the current graphics device is. DWF |
---|
| 108 | ; 1/27/97: Added the RIGHT and TOP keywords. Also modified the |
---|
| 109 | ; way the TITLE keyword works. DWF |
---|
| 110 | ; 7/15/97: Fixed a problem some machines have with plots that have |
---|
| 111 | ; no valid data range in them. DWF |
---|
| 112 | ; 3/3/98: ajout du keyword discret par |
---|
[136] | 113 | ; sebastien (smasson\@lodyc.jussieu.fr) |
---|
[133] | 114 | ; |
---|
| 115 | ; @version $Id$ |
---|
| 116 | ; |
---|
[2] | 117 | ;- |
---|
[136] | 118 | PRO COLORBAR, BOTTOM=bottom, CB_CHARSIZE=cb_charsize, $ |
---|
| 119 | CB_CHARTHICK=cb_charthick $ |
---|
[2] | 120 | , CB_COLOR=cb_color, $ |
---|
[133] | 121 | DIVISIONS=divisions, DISCRETE=discrete,CB_LABEL = cb_label, $ |
---|
[136] | 122 | FORMAT=format, POSITION=position, MAX=max, MIN=min, $ |
---|
| 123 | NCOLORS=ncolors, $ |
---|
| 124 | PSCOLOR=pscolor, CB_TITLE=cb_title, NOTITLE=notitle, $ |
---|
| 125 | VERTICAL=vertical, $ |
---|
| 126 | TOP=top, RIGHT=right, CB_LOG = CB_log, _extra = ex |
---|
| 127 | ; Is the Postscript device selected? |
---|
[114] | 128 | ; |
---|
| 129 | compile_opt idl2, strictarrsubs |
---|
| 130 | ; |
---|
[2] | 131 | |
---|
| 132 | postScriptDevice = (!D.NAME EQ 'PS') |
---|
| 133 | |
---|
| 134 | ; Check and define keywords. |
---|
| 135 | |
---|
| 136 | IF N_ELEMENTS(ncolors) EQ 0 THEN BEGIN |
---|
| 137 | |
---|
| 138 | ; Most display devices to not use the 256 colors available to |
---|
| 139 | ; the PostScript device. This presents a problem when writing |
---|
| 140 | ; general-purpose programs that can be output to the display or |
---|
| 141 | ; to the PostScript device. This problem is especially bothersome |
---|
| 142 | ; if you don't specify the number of colors you are using in the |
---|
| 143 | ; program. One way to work around this problem is to make the |
---|
| 144 | ; default number of colors the same for the display device and for |
---|
| 145 | ; the PostScript device. Then, the colors you see in PostScript are |
---|
| 146 | ; identical to the colors you see on your display. Here is one way to |
---|
| 147 | ; do it. |
---|
| 148 | |
---|
| 149 | IF postScriptDevice THEN BEGIN |
---|
| 150 | oldDevice = !D.NAME |
---|
| 151 | |
---|
| 152 | ; What kind of computer are we using? SET_PLOT to appropriate |
---|
| 153 | ; display device. |
---|
| 154 | |
---|
| 155 | thisOS = !VERSION.OS_FAMILY |
---|
| 156 | thisOS = STRMID(thisOS, 0, 3) |
---|
| 157 | thisOS = STRUPCASE(thisOS) |
---|
| 158 | CASE thisOS of |
---|
| 159 | 'MAC': SET_PLOT, thisOS |
---|
| 160 | 'WIN': SET_PLOT, thisOS |
---|
| 161 | ELSE: SET_PLOT, 'X' |
---|
| 162 | ENDCASE |
---|
| 163 | !p.BACKGROUND=(!d.n_colors-1) < 255 |
---|
| 164 | !p.color=0 |
---|
| 165 | if !d.n_colors gt 256 then !p.background='ffffff'x |
---|
| 166 | |
---|
| 167 | ; Open a window (to make sure !D.N_COLORS is accurate). |
---|
| 168 | |
---|
| 169 | WINDOW, /FREE, /PIXMAP, XSIZE=10, YSIZE=10 |
---|
| 170 | WDELETE, !D.WINDOW |
---|
| 171 | |
---|
| 172 | ; Here is how many colors we should use. |
---|
| 173 | |
---|
| 174 | ncolors = !D.N_COLORS |
---|
| 175 | SET_PLOT, oldDevice |
---|
| 176 | IF oldDevice EQ 'X' OR oldDevice EQ 'MAC' OR oldDevice EQ 'WIN' then BEGIN |
---|
| 177 | !p.BACKGROUND=(!d.n_colors-1) < 255 |
---|
| 178 | !p.color=0 |
---|
| 179 | if !d.n_colors gt 256 then !p.background='ffffff'x |
---|
| 180 | ENDIF |
---|
| 181 | ENDIF ELSE ncolors = !D.N_COLORS |
---|
| 182 | ENDIF |
---|
| 183 | IF N_ELEMENTS(bottom) EQ 0 THEN bottom = 0B |
---|
| 184 | IF N_ELEMENTS(cb_charsize) EQ 0 THEN cb_charsize = 1.0 |
---|
| 185 | IF N_ELEMENTS(cb_charthick) EQ 0 THEN cb_charthick = 1.0 |
---|
| 186 | IF N_ELEMENTS(format) EQ 0 THEN format = '(F6.2)' |
---|
| 187 | IF N_ELEMENTS(cb_color) EQ 0 THEN cb_color = ncolors - 1 + bottom |
---|
| 188 | IF N_ELEMENTS(min) EQ 0 THEN min = 0.0 |
---|
| 189 | IF N_ELEMENTS(max) EQ 0 THEN max = FLOAT(ncolors) - 1 |
---|
| 190 | IF N_ELEMENTS(divisions) EQ 0 THEN divisions = 2 |
---|
| 191 | IF N_ELEMENTS(cb_title) EQ 0 THEN cb_title = '' |
---|
| 192 | IF N_ELEMENTS(notitle) EQ 1 THEN cb_title = '' |
---|
| 193 | pscolor = KEYWORD_SET(pscolor) |
---|
| 194 | |
---|
| 195 | IF KEYWORD_SET(vertical) THEN BEGIN |
---|
[133] | 196 | IF KEYWORD_SET(discrete) THEN begin |
---|
| 197 | facteur=256/n_elements(discrete) |
---|
[136] | 198 | discrete=reform(replicate(1,facteur) # discrete,facteur*n_elements(discrete), /overwrite) |
---|
[133] | 199 | bar = REPLICATE(1B,10) # discrete |
---|
[2] | 200 | endif else bar = REPLICATE(1B,10) # BINDGEN(256) |
---|
| 201 | IF N_ELEMENTS(position) EQ 0 THEN position = [0.88, 0.15, 0.95, 0.95] |
---|
| 202 | ENDIF ELSE BEGIN |
---|
[133] | 203 | IF KEYWORD_SET(discrete) THEN begin |
---|
| 204 | facteur=256/n_elements(discrete) |
---|
[136] | 205 | discrete=reform(replicate(1,facteur) # discrete,facteur*n_elements(discrete), /overwrite) |
---|
[133] | 206 | bar = discrete # REPLICATE(1B,10) |
---|
[2] | 207 | endif else bar = BINDGEN(256) # REPLICATE(1B, 10) |
---|
| 208 | IF N_ELEMENTS(position) EQ 0 THEN position = [0.15, 0.88, 0.95, 0.95] |
---|
| 209 | ENDELSE |
---|
| 210 | |
---|
| 211 | ; Scale the color bar. |
---|
[133] | 212 | IF NOT KEYWORD_SET(discrete) THEN $ |
---|
[2] | 213 | bar = BYTSCL(bar, TOP=ncolors-1) + bottom |
---|
| 214 | |
---|
| 215 | ; Get starting locations in DEVICE coordinates. |
---|
| 216 | |
---|
[114] | 217 | xstart = position[0] * !D.X_VSIZE |
---|
| 218 | ystart = position[1] * !D.Y_VSIZE |
---|
[2] | 219 | |
---|
| 220 | ; Get the size of the bar in DEVICE coordinates. |
---|
| 221 | |
---|
[114] | 222 | xsize = (position[2] - position[0]) * !D.X_VSIZE |
---|
| 223 | ysize = (position[3] - position[1]) * !D.Y_VSIZE |
---|
[2] | 224 | |
---|
| 225 | ; For PostScript output only, draw the annotation in !P.COLOR |
---|
| 226 | ; unless "pscolor" is set. This makes better output on grayscale |
---|
| 227 | ; printers. |
---|
| 228 | |
---|
| 229 | IF postScriptDevice AND (pscolor NE 1) THEN BEGIN |
---|
| 230 | oldcolor = cb_color |
---|
| 231 | cb_color = !P.COLOR |
---|
| 232 | ENDIF |
---|
| 233 | |
---|
| 234 | ; Display the color bar in the window. Sizing is |
---|
| 235 | ; different for PostScript and regular display. |
---|
| 236 | |
---|
| 237 | IF postScriptDevice THEN BEGIN |
---|
| 238 | |
---|
| 239 | TV, bar, xstart, ystart, XSIZE=xsize, YSIZE=ysize |
---|
| 240 | |
---|
| 241 | ENDIF ELSE BEGIN |
---|
| 242 | |
---|
| 243 | bar = CONGRID(bar, CEIL(xsize), CEIL(ysize), /INTERP) |
---|
| 244 | TV, bar, xstart, ystart |
---|
| 245 | |
---|
| 246 | ENDELSE |
---|
| 247 | |
---|
| 248 | ; Annotate the color bar. |
---|
| 249 | |
---|
| 250 | if keyword_set(cb_label) then begin |
---|
| 251 | divisions = n_elements(cb_label)-1 |
---|
| 252 | for i = 0,divisions DO cb_label = string(cb_label, FORMAT = format) |
---|
| 253 | format = '' |
---|
| 254 | ENDIF ELSE cb_label = '' |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | IF KEYWORD_SET(vertical) THEN BEGIN |
---|
| 258 | |
---|
| 259 | IF KEYWORD_SET(right) THEN BEGIN |
---|
| 260 | |
---|
| 261 | PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ |
---|
| 262 | YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ |
---|
| 263 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize, CHARTHICK=cb_charthick $ |
---|
| 264 | , /NOERASE, $ |
---|
| 265 | YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ |
---|
| 266 | YRANGE=[min, max], YTITLE=cb_title |
---|
| 267 | |
---|
| 268 | AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT=format, YTICKS=divisions, $ |
---|
| 269 | YTICKLEN=0.1, YSTYLE=1, COLOR=cb_color, CHARTHICK=cb_charthick $ |
---|
[19] | 270 | , CHARSIZE=cb_charsize, xtickname = cb_label, ylog = cb_log |
---|
[2] | 271 | |
---|
| 272 | ENDIF ELSE BEGIN |
---|
| 273 | |
---|
| 274 | PLOT, [min,max], [min,max], /NODATA, XTICKS=1, $ |
---|
| 275 | YTICKS=divisions, XSTYLE=1, YSTYLE=9, $ |
---|
| 276 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ |
---|
| 277 | , CHARTHICK=cb_charthick, /NOERASE, $ |
---|
| 278 | YTICKFORMAT=format, XTICKFORMAT='(A1)', YTICKLEN=0.1 , $ |
---|
| 279 | YRANGE=[min, max], xtickname = cb_label |
---|
| 280 | |
---|
| 281 | AXIS, YAXIS=1, YRANGE=[min, max], YTICKFORMAT='(A1)', YTICKS=divisions, $ |
---|
| 282 | YTICKLEN=0.1, YTITLE=cb_title, YSTYLE=1, COLOR=cb_color $ |
---|
[19] | 283 | , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, ylog = cb_log |
---|
[2] | 284 | |
---|
| 285 | ENDELSE |
---|
| 286 | |
---|
| 287 | ENDIF ELSE BEGIN |
---|
| 288 | |
---|
| 289 | IF KEYWORD_SET(top) THEN BEGIN |
---|
| 290 | |
---|
| 291 | PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ |
---|
| 292 | YTICKS=1, XSTYLE=9, YSTYLE=1, $ |
---|
| 293 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ |
---|
| 294 | , CHARTHICK=cb_charthick, /NOERASE, $ |
---|
| 295 | YTICKFORMAT='(A1)', XTICKFORMAT='(A1)', XTICKLEN=0.1, $ |
---|
| 296 | XRANGE=[min, max], XTITLE=cb_title |
---|
| 297 | |
---|
| 298 | AXIS, XTICKS=divisions, XSTYLE=1, COLOR=cb_color $ |
---|
| 299 | , CHARSIZE=cb_charsize, CHARTHICK=cb_charthick, $ |
---|
[19] | 300 | XTICKFORMAT=format, XTICKLEN=0.1, XRANGE=[min, max], XAXIS=1, xtickname = cb_label, xlog = cb_log |
---|
[2] | 301 | |
---|
| 302 | ENDIF ELSE BEGIN |
---|
| 303 | |
---|
| 304 | PLOT, [min,max], [min,max], /NODATA, XTICKS=divisions, $ |
---|
| 305 | YTICKS=1, XSTYLE=1, YSTYLE=1, $ |
---|
| 306 | POSITION=position, COLOR=cb_color, CHARSIZE=cb_charsize $ |
---|
| 307 | , CHARTHICK=cb_charthick, /NOERASE, $ |
---|
| 308 | YTICKFORMAT='(A1)', XTICKFORMAT=format, XTICKLEN=0.1, $ |
---|
[19] | 309 | XRANGE=[min, max], TITLE=cb_title, xtickname = cb_label, xlog = cb_log |
---|
[2] | 310 | |
---|
| 311 | ENDELSE |
---|
| 312 | |
---|
| 313 | ENDELSE |
---|
| 314 | ; Restore color variable if changed for PostScript. |
---|
| 315 | |
---|
| 316 | IF postScriptDevice AND (pscolor NE 1) THEN cb_color = oldcolor |
---|
| 317 | |
---|
| 318 | return |
---|
| 319 | END |
---|