Brewer Colors in IDL

QUESTION: I really like those colors Cynthia Brewer has designed for mapping purposes. They are beautiful, and I can use them in a number of different applications. Is there some way I can access those colors as color tables in IDL?

ANSWER: Yes, Mike Galloy first alerted us to Brewer Colors and produced a color table file with these colors. Unfortunately, there were a couple of small problems with the color tables that Mike produced. (Although I am extremely grateful for all the hard work Mike did to produce the color tables originally.) In particular, the diverging color tables did not diverge in the middle of the color table (at colors 127 and 128), but rather diverged at colors 117 and 118. There was also a problem at the high end of the color table that became apparent when the color table was reduced to say 16 colors. In that case, colors 15 and 16 were indistinguishable. I have slightly modifed the color tables Mike originally produced to fix both of these problems. The colors now diverge in the proper location, and the darker colors are not over-represented at the high end of the color table scale. I have placed 27 of these original color tables, with corrections, in the file fsc_brewer.tbl.

To use this file with the color tools described below, the file should be placed in the $IDL_DIR/resource/colors directory in your IDL distribution (the preferred location), or in the same directory that contains the source code for the color tools below (e.g., the coyote directory).

Using Brewer Colors

Once the brewer color table file (fsc_brewer.tbl) has been downloaded, you can use it with the normal IDL color tools, such as LoadCT and XLoadCT, by specifying the name of the file using the FILE keyword. Assuming you have put the color table file in the preferred place in the IDL distribution, you could type these commands.

   IDL> colorFile = Filepath(SUBDIRECTORY=['resource','colors'], 'fsc_brewer.tbl')
   IDL> LoadCT, 20, FILE=colorFile    IDL> XLoadCT, FILE=colorFile 

It is a bit easier to use the Brewer Color Tables with the color tools from the Coyote Library (CIndex, cgLoadCT, cgColor, cgPickColorName, PickColor, XColors), in that you only have to set the BREWER keyword to use these Brewer colors and color tables. (Note, you may have to download new files from the Coyote Library to use this keyword, and that these color tools often use other programs from the Library.)

   IDL> cgLoadCT, 20, /BREWER    IDL> color = cgColor('red5')
   IDL> color = PickColor()    IDL> colorName = cgPickColorName()
   IDL> XColors, /BREWER 

To see a selection of the brewer colors available, type these commands.

   IDL> index = [1, 3, 4, 7, 9, 13, 14, 16, 18, 19, 20, 21, 22, 24, 25, 26]
   IDL> FOR j=0,16 DO cgLoadCT, index[j], NCOLORS=16, BOTTOM=16*j, /BREWER
   IDL> CIndex, /BREWER 

You see the result in the figure below. Continuous color tables are shown in the bottom 8 rows, and diverging color tables are shown in the top eight rows. All color tables have been reduced to 16 colors for this figure.

A selection of Brewer color tables.
This is a selection of the Brewer color tables, with both continuous and
diverging color tables reduced to 16 colors each.

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

Web Coyote's Guide to IDL Programming