Unwanted Colors in Coyote Graphics Output
QUESTION: I keep getting these unwanted colors in my color bar. I have no idea why they show up or what I can do to get rid of them. Can you help me?
Here is the Coyote Graphics code I am using.
cgLoadCT, 0 cgImage, image, /Keep_Aspect, Position=[0.1, 0.1, 0.9, 0.8], $ XRange=[-1,1], YRange=[-1,1], /Axes cgPlot, [ 0,0], [-1,1], Thick=2, /Overplot, Color=cgColor('red') cgPlot, [-1,1], [ 0,0], Thick=2, /Overplot, Color=cgColor('purple') cgColorbar, /Fit
And here is the result.
|Extra and unwanted colors are showing up in the color bar.|
ANSWER: There are several ways to answer this question. At heart, this is a color table contamination problem. Between the time you loaded the colors in the one physical color table, and the time you used the colors in the cgColorbar program, someone else had loaded colors in the color table, thereby contaminating it. From the the colors, it is easy to guess the culprits: the two cgPlot commands.
This kind of problem is common when working in indexed color mode, and is one reason I encourage everyone to move into the 21st century and stop doing it. So, there are two easy solutions to your program. (1) Switch to decomposed color mode and run this program, or (2) load the colors you want to see in the color table just before you run the cgColorbar command. But, these solutions don't really get to the heart of the matter.
You may have heard that Coyote Graphics routines are color model independent. And, this is true. Mostly, they don't care what color model you use when you run them, they do all of their work in decomposed color, if they possible can. This way they can use colors directly and never have to load colors in the color table, avoiding these color contamination issues. But, why are they clearly contaminating the color table here?
The answer is because you are specifying colors in these cgPlot commands incorrectly. You are passing the color names through the cgColor command to get the colors into the cgPlot command.
cgPlot, [ 0,0], [-1,1], Thick=2, /Overplot, Color=cgColor('red') cgPlot, [-1,1], [ 0,0], Thick=2, /Overplot, Color=cgColor('purple')
What you should be doing instead is passing the color names directly to the cgPlot command like this.
cgPlot, [ 0,0], [-1,1], Thick=2, /Overplot, Color='red' cgPlot, [-1,1], [ 0,0], Thick=2, /Overplot, Color='purple'
This way the conversion takes place inside the cgPlot command, where the program is using decomposed color, and a 24-bit value is used to specify the color directly, thereby avoiding the color table. When cgColor is used in indexed color mode, it must load the color into the color table, and return that index, which is passed to cgPlot. What you are trying to do, always, is to avoid loading drawing colors in a color table that is reserved for images.
The bottom line is that simply removing the call to cgColor from Coyote Graphics routines allows them to work in a way that is in your best interest. As opposed to, say, your colleagues, who keep encouraging you to put that Device, Decomposed=0 command in your IDL start-up file!
Version of IDL used to prepare this article: IDL 7.1.2.