NCL Home > Documentation > Graphics > Graphical Interfaces


Given the number of desired color values, return an array of RGB triplets or RGBA quadruplets that nicely span the given color map.

Available in version 6.2.0 and later.


load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"

	function span_color_rgba (
		color_map      ,           
		num_colors [1] : integer   



An NCL predefined color map (like "rainbow", "BlueRed", "matlab_jet"), an RGB array, or an RGBA array.


The number of color values you want returned.

Return value

An array of RGB or RGBA values from the given color map.


This function uses the same spanning algorithm that NCL uses to choose colors for a filled contour or vector plot, given a particular color map. It looks at the number of colors you want and the size of your color map, and creates a "nice" span across the color map such that it starts at the very first color and ends at the very last color.

This function can be useful, for example, if you are drawing a scatter plot, where you need to color groups of markers based on some range of data they fall in.

This function will return RGBA values if you give it an RGBA array or a predefined color map, and RGB values if you give it an array of RGB values. If you give it a predefined color map, the first two colors (background and foreground colors) will not be included.

To have color index values returned instead, use span_color_indexes.

See Also

span_color_indexes, get_color_index, get_color_rgba, span_named_colors


Coming soon.