How to handle colors in IDL, the MODERN way:

With a bit of experimentation, and an equal measure of perusing Dave Fanning's excellent web page (especially here and here), I have finally figured out how to get colors in IDL to behave in a reasonable way. On a 24-bit display, I can now get color tables working correctly in plots, and yet I can also use any color I want at any time, too. Here's how:

  1. Have a 24-bit color display.

    (Make sure that X windows is configured for 24-bit True Color; this is the default on a Mac but can be changed in the X11 preferences. Leave it at the default.)

  2. Load IDL with color decomposition enabled. This is true by default, but just to be on the safe side, put this in your idl startup file:
  3. Don't use TV. TV is ancient and doesn't honor color tables in 24 bit color decomposed mode. Use a smart replacement such as TVIMAGE or IMDISP instead. If you really want to use something like tv, try TVIMAGE with the /TV compatibility switch. (what happens here is that TVIMAGE and IMDISP automatically handle changing the decomposed setting back and forth behind the scenes for you.)
  4. To pick out individual colors by name, either
    1. use hex color triplets.
    2. use Dave Fanning's FSC_COLOR (or an equivalent).

      Try "color = fsc_color(/select)" to see a dialog with the full color list.

  5. That's it! Here's a demo:
    		xyouts,150,150,"More Data!",color=fsc_color('turquoise')
    		plot,sin(findgen(100)/10),color=fsc_color('orange red')
    		xyouts,30,0.5,"A Sin Wave",color=fsc_color('Dodger Blue')
    which produces the following:

  6. Actually, that's not quite it. There's a complication when dealing with Postscript, in that IDL supports 24 bit color for images in Postscript, but does NOT support 24 bit color for line drawings and plots in Postscript. So you cannot use 24-bit codes to specify such colors. fsc_color() does work properly for Postscript, but if you're outputting multiple Postscript files, you need to re-invoke fsc_color AFTER the psopen() call for each file to set the colors for that file.

    Note that this lack of support for 24-bit color in postscript plots is pretty much inexcusable brokenness on the part of RSI/ITTVIS. Humbug.

This page last modified by Marshall 2005-12-09