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:
- 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.)
- 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:
device,decomposed=1
- 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.)
- To pick out individual colors by name, either
- use hex color triplets.
- use Dave Fanning's FSC_COLOR (or an equivalent).
Try "color = fsc_color(/select)" to see a dialog with the full color list.
- That's it! Here's a demo:
!p.multi=[0,2,2] loadct,3 imdisp,dist(200),/axis,color=fsc_color('pink') xyouts,50,50,"Data!",color='00BB10'x xyouts,150,150,"More Data!",color=fsc_color('turquoise') loadct,5 tvimage,dist(100),/keep_aspect plot,sin(findgen(100)/10),color=fsc_color('orange red') xyouts,30,0.5,"A Sin Wave",color=fsc_color('Dodger Blue') contour,dist(256),color='FF00A0'x,/xs,/yswhich produces the following:

-
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