Fanning Software Consulting

Object Graphics Colorbars

QUESTION: I want to create a colorbar in object graphics. Can you show me how?

ANSWER: Research Systems provided a colorbar object in IDL 5.1 (IDLgrColorbar), but I find it non-intuitive and difficult to use. In particular, I find it hard to include a real-world range on the colorbar while positioning it properly. If you want to see the RSI colorbar object in action, you can look at the program XCONTOUR, which had the code for an RSI colorbar written into it, but commented out. (Partly this is because of a new error introduced into the RSI colorbar code in IDL 5.4).

Because I prefer to set the range of my colorbars and position them in a more natural way, I wrote my own colorbar objects. They are named VCOLORBAR and HCOLORBAR. They produce a vertical and horizontal colorbar, respectively.

Here is an example of how they can be used. You will need the program OWINDOW, which you can download here, to execute the code below.

PRO Colorbar_Example

 ; Create object model and view.

thisView = Obj_New('IDLgrView', Viewplane_Rect=[0, 0, 1, 1], Color=[100,100,100])
thisModel = Obj_New('IDLgrModel')

   ; Load a color table. Get color table vectors.

LoadCT, 5
TVLCT, r, g, b, /Get

   ; Create a color palette.
   
cPalette = Obj_New('IDLgrPalette', r, g, b)

   ; Create a horizontal colorbar.

horizontalCBar = Obj_New('HColorBar', Palette=cPalette, Range=[50, 350], $
   Position=[0.1, 0.8, 0.9, 0.85], Title='Horizontal Colorbar')
   
   ; Create a vertical colorbar.

verticalCBar = Obj_New('VColorBar', Palette=cPalette, Range=[0, 1000], $
   Position=[0.45, 0.1, 0.55, 0.6], Title='Vertical Colorbar')

   ; Link graphics hierarchy and view it.
   
thisModel->Add, horizontalCBar
thisModel->Add, verticalCBar
thisView->Add, thisModel
thisWindow = OWindow(thisView)
END

Here are the two colorbars produced by the code above.

Horizontal and vertical colorbars.

Google
 
Web Coyote's Guide to IDL Programming