Fanning Software Consulting

Selecting a PostScript Background Color

QUESTION: I can get any background color I like in my PostScript file as long as as I really like white. Is there any way I can get a background color other than white?

ANSWER: Normally when you type an IDL traditional graphics command, the window is first erased with the background color. If you are in indexed color mode when you issue the command, this is normally the color loaded into index 0 of the current color table. The graphic is normally drawn with the color loaded into index 255 of the current color table. For most IDL display windows, this results in a white plot on a black background.

These colors are reversed when you switch to the PostScript device, but then the background color is ignored because in PostScript there is no "window" to "erase". You get what you get: a white background.

You will notice, however, that when you are using Coyote Graphics commands (such as cgPlot, cgContour, and cgSurf) that the background color can be anything you like it to be. So, the question is, how is this possible?

It is done by filling the PostScript window with a color, using the IDL command PolyFill, and then drawing the graphic over the top of what is already in the window, taking care to set the NoErase keyword on the graphic command.

In other words, these commands:

   data = cgDemoData(1)
   Polyfill, [1,1,0,0,1], [1,0,0,1,1], /NORMAL, COLOR=cgColor('Honeydew')
   Plot, data, COLOR=cgColor('Black'), /NOERASE, /NODATA
   Plot, data, COLOR=cgColor('Steel Blue'), /NOERASE, XSTYLE=4, YSTYLE=4

are the equivalent of this command:

   cgPlot, data, COLOR='Steel Blue', BACKGROUND='Honeydew'

This is as true on the display as it is in a PostScript file.

Version of IDL used to prepare this article: IDL 7.0.1.

Last Updated: 30 March 2011