Extra Line in Color Bar

QUESTION: I am using the Colorbar program from your web page to put a color bar on my display graphic. But there is always an extra line (and always the same color as the color bar annotation) in the color bar. Where does this come from and why is it there? Here is the code I am using.

   Erase, Color=FSC_Color('ivory')
   LoadCT, 0, /Silent
   image = Dist(200)
   s = Size(image, /Dimensions)
   pos = [0.1, 0.1, 0.8, 0.9]
   TVImage, BytScl(image), Position=pos, /Keep_Aspect
   Colorbar, Range=[Min(image), Max(image)], Color=FSC_Color('firebrick'), /Vertical

You can see the line in the color table in the figure below at value 224.

An extraneous line shown in the color bar.
An extraneous line is shown in the color bar.
 

ANSWER: This problem is caused by the color model you are using (indexed color, or color decomposition turned off) in conjuction with the way FSC_Color and, to a lesser extent, Colorbar work together. Notice that the problem will go away, at least on your display, by turning color decomposition on:

   Device, Decomposed=1
   Erase, Color=FSC_Color('ivory')
   LoadCT, 0, /Silent
   image = Dist(200)
   s = Size(image, /Dimensions)
   pos = [0.1, 0.1, 0.8, 0.9]
   TVImage, BytScl(image), Position=pos, /Keep_Aspect
   Colorbar, Range=[Min(image), Max(image)], Color=FSC_Color('firebrick'), /Vertical

Of course, this won't help you much if you are using a device, such as the PostScript device, which can only use an indexed color model. So it will help to understand the problem at a deeper level.

Suppose you are using an indexed color model. Then FSC_Color has to turn the color "firebrick" into a color index number and load that particular color at that index in the color table. The index it chooses, given the way you are calling FSC_Color, is index number 224. Unfortunately, the call to FSC_Color must be resolved, and the drawing color loaded into the current color table, before IDL can execute the Colorbar program, which simply uses the colors currently loaded in the color table. Thus, by the time Colorbar is run, the wrong color is in the color table.

Note that with color decomposition on, FSC_Color doesn't need to load a color in the color table, it simply returns a 24-bit value that encodes the color and can be used directly. This is why the solution above works. The color table is not changed by the FSC_Color program and is the same as it was for the TVImage call prior to the Colorbar call.

This suggests another way to solve this problem, if (and only if) the annotation color for the color bar is in the current color table. It is not, in this case, but suppose you wanted to draw the annotation in black. With color table 0, the black color is color index number 0, so the problem could be "solved" by using color index 0 as the annotation color. This is done by using the second positional parameter to FSC_Color, which is the index number where the specified color is to be loaded.

   Device, Decomposed=0
   Erase, Color=FSC_Color('ivory')
   LoadCT, 0, /Silent
   image = Dist(200)
   s = Size(image, /Dimensions)
   pos = [0.1, 0.1, 0.8, 0.9]
   TVImage, BytScl(image), Position=pos, /Keep_Aspect
   Colorbar, Range=[Min(image), Max(image)], Color=FSC_Color('black', 0), /Vertical

But, of course, here we want the annotation color to be different from the colors used for the image. When this is the case, it is customary to divide the color table up into "image colors" and "drawing colors" (sometimes called "annotation colors"). We could, for example, use 255 colors for the image and one for the annotation color. The code would look like this.

   Device, Decomposed=0
   Erase, Color=FSC_Color('ivory')
   LoadCT, 0, /Silent, NColors=255
   image = Dist(200)
   s = Size(image, /Dimensions)
   pos = [0.1, 0.1, 0.8, 0.9]
   TVImage, BytScl(image, Top=254), Position=pos, /Keep_Aspect
   Colorbar, Range=[Min(image), Max(image)], NColors=255, $
      Color=FSC_Color('firebrick', 255), /Vertical

You can see the results in the figure below. Note that this code will work correctly no matter what color model you choose to use. Thus, this is the correct way to write device-independent color code when you are specifying the annotation color with FSC_Color.

No extraneous line shown in the color bar.
Now there is no extraneous line shown in the color bar.
 

ColorBar Update

The ColorBar program has been re-written with an AnnotateColor keyword to help solve this problem. Thus, one other way to fix this problem is to use code like this.

   Erase, Color=FSC_Color('ivory')
   LoadCT, 0, /Silent
   image = Dist(200)
   s = Size(image, /Dimensions)
   pos = [0.1, 0.1, 0.8, 0.9]
   TVImage, BytScl(image), Position=pos, /Keep_Aspect
   Colorbar, Range=[Min(image), Max(image)], AnnotateColor='firebrick', /Vertical

Google
 
Web Coyote's Guide to IDL Programming