PyNGL Home > Functions > Color routines


Returns the color index whose associated color on the given workstation is closest to the color name supplied.


cindex = Ngl.get_named_color_index(wks, color_name)



The identifier returned from calling Ngl.open_wks.


A color name from the rgb.txt file.

Return value


An integer representing a color index into the current colormap that contains the closest color match found.


This function looks up the RGB value for the given color name in the rgb.txt file, and returns the index value of the closest match of this RGB value in the color map of the given workstation.

If an invalid color name is given, then the color index returned will be negative.

Click here to see a visual representation of all 650 named colors.

See Also

Ngl.new_color, Ngl.set_color, Ngl.draw_colormap


For a simple example of using Ngl.get_named_color_index, run the following Python script:

import Ngl

wks = Ngl.open_wks("x11","example")

# Draw the current color map.

# Retrieve the color indices for red and brown.
red   = Ngl.get_named_color_index(wks,"red")
brown = Ngl.get_named_color_index(wks,"brown")

# Retrieve the color map so that we can determine 
# the RGB values for red and brown.
cmap = Ngl.retrieve_colormap(wks)

# Print the color indices for red and brown along 
# with their associated RGB values.
fmt = "red is color index %4d and has RGB values = " + str(cmap[red])
print fmt % (red)
fmt = "brown is color index %4d and has RGB values = " + str(cmap[brown])
print fmt % (brown)


Red is color index 189 in the default color map. Brown is not a color in the default color map; the closest color that is found is color index 182, which is not really a very good match visually.