Data files for some examples
Example pages containing:
List of available color tables
To reverse a color table, see example
6 on the label bar page.
To add a color (gray) to a colormap, see
gsn_define_colormap is the primary
mean of specifying a colormap. This function will accept a built-in
NCL named colormap (example 7 and example 2), an array of
term="NamedColor">named colors (example 4), and an array of
rgb triplets (example 12).
The 650 valid named colors and the corresponding RGB triplets are
listed in "$NCARG_ROOT/lib/ncarg/database/rgb.txt."
There's also a separate page for dealing with color maps.
: Demonstrates turning on
color with the default color map.
cnFillOn = True, turns on the
: Example of using
a built in colormap. Also demonstrates adding gray to a colormap
for the continents if needed.
gsn_define_colormap is the procedure
used to set a colormap for the given workstation. There are numerous
color tables to
Setting gsnSpreadColors=True will use all
the colors in a color map when creating a filled contour or vector
plot. In NCL version 6.1.0, you no longer need to set this resource to
True, as the colors will be spanned automatically. In NCL versions
6.0.0 and earlier, the default is to start with the first color and
use them in sequence.
New resources were introduced in V6.1.0 allowing you to turn off the
automatic span, and allowing you to specify a color palette to use
with your contours (independent of the workstation color map):
For best results when using the blue/red color spectrum, manually set
the contour levels so that the change centers on zero:
cnLevelSelectionMode = "ManualLevels"
In NCL versions 6.0.0 or earlier, if you use a colormap that does
not have gray in it, you have to add that color if you want the
continental fill to be gray.
NhlNewColor(wks,0.8,0.8,0.8) will add the gray. In
NCL versions 6.1.0 or later, named colors do not have to be added.
Demonstrates how to select just a few colors out of a large
colormap and make one of those colors transparent.
cnFillColors is the resource used
to select what colors out of a colormap you want to represent each
contour in the plot.
The -1 indicates that the color is transparent. This is not a true
color per say but rather the absence of color. As such, whatever color
the background is will be seen.
: Creates a panel plot with
its own label bar.
gsnPanelLabelBar = True
Note that this resource should be passed only to gsn_panel.
You can see other examples of panel plots and common label bars on the
special topics panel page.
: Creates a color plot
with uneven color intervals.
cnLinesOn = False, turns off
and cnLevels =
manually sets the uneven contour levels.
: Another example of
choosing from a set of predefined color maps. Zonal average
automatically calculated and plotted. The label bar is moved from the
default horizontal to vertical.
Selects the "uniform" predefined color map. There are numerous
tables to choose from.
lbOrientation = "Vertical", Creates
a vertical label bar.
gsnZonalMean = True, Automatically
calculates and draws the zonal mean of the field. gsnZonalMeanXMaxF and gsnZonalMeanXMinF allow the user to change the
axis of the zonal average plot.
: Merges two
colormaps using gsn_merge_colormaps
so that multiple colormaps can be used on the same workstation.
Note that in V6.1.0, you do not need to merge colormaps in this
way. If you are drawing color contours, vectors, or streamlines, you
can associate a colormap with a plot using one of these new resources:
See the color_9_new.ncl script
for an examples of
: I randomly chose
colors from the master list of named
, and placed them in my own RGB file (test_rgb.txt
) to create a personalized
RGBtoCmap is the function that
will take a text file of RGB triplets and convert them into an NCL
colormap. You can then use gsn_draw_colormap to preview what your
colormap looks like. This is an easy way to develop your own
: The American
Geophysical Union (AGU) is now requiring all figures submitted for
publication to be in CMYK color. This is easily done in NCL.
type = "ps"
type@wkColorModel = "cmyk"
wks = gsn_open_wks
pass the variable to the workstation routine.
This example, along with many others throughout this web site use
three resources to specify how a color table is used. gsnSpreadColors will ensure that the full range
of the colormap is used. Otherwise, NCL will take each color in turn
and you may end up with an all blue plot for instance if you used a
blue_red color table.
gsnSpreadColorStart allows you to choose
which color to start your color table at while gsnSpreadColorEnd allows you to choose which
color to end your color table.
: Demonstrates choosing
a colormap based upon the specification of an array of RGB triplets.
The array must be a float array, and must be normalized by dividing by
This particular color map is specifically used for precipitation plots.
how to convert an array of colors in HSV format to RGB format.
hsvrgb is the function that does
the conversion. See the script for usage. hsvrgb,
available in version 4.3.2 or later,
replaces the obsolete function hsv2rgb.
: Uses symMinMaxPlt
to automatically calculate
symmetric min/max/int values for use with a symmetric colormap. This
is useful when running a script that plots multiple variables of
: Uses gsn_retrieve_colormap
to retrieve a colormap
and changes one of the colors.
An alternative to this method is to use the function
NhlNewColor, which can be used to add a color to
the existing colormap, if that colormap has less than 255 colors. 255
is the maximum number of defined colors in a colormap in NCL.
: Draws the given list
of named colors using gsn_draw_named_colors
. This procedure
internally sets the colormap to the given list of named colors,
and then sets the color map back to the original color map before
exiting. It is mostly useful for debugging purposes.
If you need to set your color map using named colors, see