How to use the handy new named colors in NCL . . .
![]() Mary Haley
|
by Mary Haley This article is geared to current NCAR Graphics users who are using the NCAR Command Language (NCL) to generate graphics for scientific visualization. The new named colors are included in version 4.1.1 of NCAR Graphics, which is scheduled for release this summer -- but you if you have version 4.1 and would like to use named colors right now, you can do so by getting an updated copy of NCL. Simply send email to ncargfx@ucar.edu to receive the new NCL with this capability. Blanched Almond. Peach Puff. Lemon Chiffon. Papaya Whip. Mint Cream. The NCAR cafeteria's frozen yogurt flavors of the week? No! They are some of the 650 unique new named colors you can now use in the NCAR Command Language (NCL) to define line colors, font colors, map fill colors, contour level colors, and other color-specific items in your graphical output. Previously, to set the color of a particular aspect of your plot, you had to use a color index value that represented a color defined in your current color map -- for instance, "1.00,1.00,1.00." Now, with the use of named colors , you have the option of setting colors by name as well -- for instance, "white." To see a list of the new named colors (from AliceBlue to YellowGreen), click here. To see the actual colors, click here. This article shows different ways to use named colors, provides several actual NCL code examples, and offers some important notes on usage.
Getting set upTo run the NCL examples in this article, you must either have your own copy of the updated version of NCL (to get a copy, send email to ncargfx@ucar.edu) or run the examples on SCD's Silicon Graphics Origin 2000 (dataproc). For information on how to set up your environment to run NCL on dataproc, see the NCAR Graphics section in the SCD UserDoc "Getting started on dataproc."Note: The following examples use some special plotting functions that are documented in the "Getting started using NCL (GSUN)" user guide; for more information on GSUN's easy-to-use interface to NCL, see "GSUN: Graphics made easier in NCL," in this issue.
How to set a single-color resourceTo use a named color when setting a color resource that previously required a color index value, replace the color index value with a color name enclosed in double quotes. For example, to set the font color of your main title to red, use the following line in your NCL script:
"tiMainFontColor" : "red"Note: The above directions apply to setting a color resource in an NCL script. If you want to use a color name in a resource file, do not use double quotes around the color name:
*tiMainFontColor : red
How to set an array color resourceTo set a resource that previously required an array of color index values, you can now use a combination of named colors and color index values, with each one enclosed in double quotes. For example, to create a filled contour plot with eight contour levels and the fill colors "Red", "DarkRed", color index 5, "GreenYellow", color index 2, "Aqua", "MediumBlue", and "RoyalBlue", you set the cnFillColors resource as follows in your NCL script:
"cnFillColors" : (/"Red", "DarkRed", "5", "GreenYellow", "2", \
"Aqua", "MediumBlue", "RoyalBlue"/)
For a description of the cnFillColors resource, see cnFillColors in the NCAR Graphics website.
How to define a color mapYou can also use named colors to define a color map. Previously, you had to define color maps with RGB triplets. Now you can optionally use a combination of RGB triplets and named colors, with each one enclosed in double quotes. For example, to set the wkColorMap resource with a combination of RGB triplets and named colors , your NCL code might look something like this:
"wkColorMap" : (/"white", "black", \
"(/1.00,0.00,0.00/)", "(/0.70,0.10,1.00/)", \
"(/0.20,1.00,0.10/)", "(/1.00,1.00,0.20/)", \
"(/1.00,0.60,0.00/)", "(/0.40,0.50,0.90/)", \
"(/1.00,0.80,0.70/)", "HotPink", "DeepSkyBlue", \
"OliveDrab", "Grey56"/)
Using the older method of RGB triplets only, you can specify the above color map with the following code:
"wkColorMap" : (/(/1.00,1.00,1.00/), (/0.00,0.00,0.00/),\
(/1.00,0.00,0.00/), (/0.70,0.10,1.00/),\
(/0.20,1.00,0.10/), (/1.00,1.00,0.20/),\
(/1.00,0.60,0.00/), (/0.40,0.50,0.90/),\
(/1.00,0.80,0.70/), (/1.00,0.41,0.71/),\
(/0.00,0.75,1.00/), (/0.60,0.80,0.20/),\
(/0.56,0.56,0.56/)/)
The RGB values for the named colors referenced above, "HotPink",
"DeepSkyBlue", "OliveDrab", and "Grey56", were calculated from the
file "rgb.txt" (which resides in the directory
$NCARG_ROOT/lib/ncarg/database). This file contains integer RGB
values for each named color, so to convert these integer values to
float values that range from 0.0 to 1.0, divide each one by 255.FYI: either one of the above code snippets would produce a color map with the following colors:
Note: For more information on color maps, RGB triplets, and wkColorMap, see their respective entries (color tables, RGB triplets, wkColorMap) in the NCAR Graphics documentation.
Two other examplesHere are two other NCL code examples of producing an XY plot and a map plot, respectively.
Important usage notes about named colors
NCAR Graphics is a registered trademark of the University Corporation for Atmospheric Research (UCAR). Reference to a company or product name does not imply approval or recommendation of that company or product to the exclusion of others. Copyright: 1987-1999 UCAR. The use of this software is governed by a license agreement. |
|||||||||||||||||