Out of Bounds Colors in Color Bars
QUESTION: I would like to be able to show out-of-bounds or out-of-range colors on my color bar. Is it possible to do this with cgColorbar?
ANSWER: Yes, it is possible with the new OOB_Low and OOB_High keywords introduced on 11 December 2011. These keywords can be set to a particular color by specifying a color name (as understood by cgColor), a byte or short integer index into the current color table, or by specifying a three-element array representing a color triple. For example, these are all valid ways to specify the color yellow for the OOB_Low color.
OOB_Low='yellow' OOB_Low = [255, 255, 0] TVLCT, 255, 255, 0, 200 OOB_Low = 200B
The OOB_Low and OOB_High colors can be set independently of one another, so you can have no out-of-range colors, just the low, or just the high, or both, as you wish.
cgDisplay, XSize=500, YSize=300 cgLoadCT, 14, /Brewer, /Reverse, NColors=100 cgColorbar, NColors=100, Position=[0.1, 0.8, 0.9, 0.85] cgColorbar, NColors=100, Position=[0.1, 0.6, 0.9, 0.65], OOB_Low='rose' cgColorbar, NColors=100, Position=[0.1, 0.4, 0.9, 0.45], OOB_High='dodger blue' cgColorbar, NColors=100, Position=[0.1, 0.2, 0.9, 0.25], OOB_Low='rose', OOB_High='dodger blue'
You see the results in the figure below.
Out of range colors can be used independently of each other. |
You may find that you also have to control the size of the triangles that are using to draw the out-of-range colors. For example, consider this simple multiplot.
!P.Multi = [0,2,1] !Y.OMargin = [1,5] cgDisplay, XSize=500, YSize=350 data1 = cgDemoData(2) data2 = cgDemoData(3) cgLoadCT, 33, NColors=8, Bottom=1 cgContour, data1, NLevels=8,/Fill, C_Colors=Indgen(8)+1 cgColorbar, NColors=7, Bottom=1, OOB_High=8B, $ OOB_Low='white', /Discrete, /Fit cgContour, data2, NLevels=8, /Fill, C_Colors=Indgen(8)+1 cgColorbar, NColors=7, Bottom=1, OOB_High=8B, $ OOB_Low='white', /Discrete, /Fit !P.OMargin = [0,0] !P.Multi=0
You see the results in the figure below.
The out-of-range triangles are too large in this multiplot. |
The out-of-range triangles are too large. You can reduce their size by using the OOB_Factor keyword. Here is a figure using the same code, but with the OOB_Factor=0.5 keyword added to the cgColorbar commands.
The triangles are reduced in size by using the OOB_Factor keyword. |
Version of IDL used to prepare this article: IDL 8.1.