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