Fanning Software Consulting

Black Background Plots

Facebook Twitter RSS

QUESTION: Sometimes when I create a plot with cgPlot or some other Coyote Graphics routine it goes into a window with a black background. On other occasions, it seems to go into a window with a white background. Can you explain how this works to me?

ANSWER: Coyote Graphics routines are designed to work in the most flexible way possible. Traditionally, people have worked with black background graphics windows in IDL. Many people still prefer to work with these graphics windows, even though working with white background graphics windows makes it significantly easier to write one IDL program that works in all devices and produces hardcopy output that looks identical to what you see on the display.

To accommodate everyone's taste. Coyote Graphics routines try to adapt themselves to what you want. If you open a traditional graphics window with a black background, using the Window command, for example, these routines will assume you like black backgrounds, and they will draw their axes and other annotations in white.

   Window, XSize=500, YSize=350
   cgPlot, cgDemoData(1)
A traditional graphics plot.
A traditional graphics plot.

If, on the other hand, you open a graphics window with a white background, the Coyote Graphics commands will assume you like white backgrounds and will draw their axes and other annotations in black.

   cgDisplay, 500, 350
   cgPlot, cgDemoData(1)
A non-traditional graphics plot.
A non-traditional graphics plot.

The Coyote Graphics commands do this by using as their default colors "Background" and "Opposite". When there is a graphics window open and it is the current graphics window, the "Background" color is selected from the pixel in the upper-right corner of the graphics window. The "Opposite" color is, well, the opposite of that color. Thus, if you have a traditional graphics window open and current, the background color is black and the opposite color is white. These colors are reversed if you have a white background graphics window open and current.

If you always wish to use white backgrounds, then you will either have to stop creating traditional windows with the Window command, or you will have to erase those windows with a white color before you display Coyote Graphics commands in them. The Coyote Graphics routine cgColor is used for this purpose.


I find it easier, however, to use cgDisplay to create and manipulate graphics windows. Windows created with cgDisplay always use a white background color.

   cgDisplay, Title='White Background Graphics Window'
   cgDisplay, WID=1, 400, 400

You might notice that when you put a Coyote Graphics command into a resizeable cgWindow, the background color is always white. It is also white if you create hardcopy output directly from a Coyote Graphics command. This is because people almost always want a white background when creating PostScript or hardcopy output. Since this operation is often done from within cgWindow, a white background is always used there.

   cgPlot, cgDemoData(1), /Window
   cgPlot, cgDemoData(1), Output='cgplot.png'

If you prefer other foreground and background colors, you may specify whatever colors you like with keywords, and you will get exactly what you want, both on the display and in your hardcopy output. That's one of the significant advantages of the Coyote Graphics system.

Note that if you issue a Coyote Graphics command and there are no graphics windows currently on the display, then a window with a white background is opened up for you. This is Coyote's way of nudging you into the 21st century.

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

Written: 6 March 2012