Re: mpFillColors and nglSpreadColors

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Thu, 21 Oct 2004 09:02:42 -0600 (MDT)

> I'm having difficulty deciphering how the colors in a colormap are assigned to
> various elements in the plot. I'm following the example from
> pynglex somewhat.
> I'm trying to figure out the colors which are assigned to the background (I
> assume element 0), foreground(1), land, ocean, etc.
> I am able to set the foreground and background correctly.
> resources = ngl.Resources()
> rlist = ngl.Resources()
> rlist.wkColorMap = 'BlueRedGray'
> ngl.set_values(wks,rlist)
> resources.mpFillOn = True # Turn on map fill.
> resources.mpLandFillColor = 254
> resources.mpOceanFillColor = -1
> This gives me a white background with black letters and a gray fill color for
> land, which is what I want. But, I also get a gray box in the "warmest"
> value for my colorbar. I have tried the nglSpreadColors resource like so ...
> resources.nglSpreadColors = True
> resources.nglSpreadColorsEnd=-2
> which I then pass to the map function ...
> map = ngl.contour_map(wks,sstma,resources) # Draw contours over a map.
> This has no effect that I can see. I thought it would tell the contour
> function to stop using the colormap at the ncol - 2 entry. Is this the wrong
> interpretation or am I doing something else?

Hi Derrick,

It looks like you are doing everything correctly. Are you using
the same colormap, "rainbow+gray"? If not, then you should check
your colormap to make sure that you don't have more than one gray
entry at the end of your colormap.

> On that note, is there a way, short of defining your own colormap as a Numeric
> array, that you can find the length of a colormap in order to know beforehand
> the indices to assign to mpOceanFillColor?

You can get the length as follows: any time after the "open_wks" call,

cmap_len = Ngl.get_integer(wks,"wkColorMapLen")

You can also draw the colormap, for debugging purposes with the
following call:


With regard to your question, however, you don't need to use index
values to specify what color you want for mpOceanFillColor. Instead,
you can use one of 650 "named" colors, if the named color is
already in your colormap. For example:

  resources.mpOceanFillColor = "DeepSkyBlue"
To see all the named colors, visit:

You can click on any of the graphics for a larger view, and also
to be able to read the name of the color. The color names
are case insensitive, so "PapayaWhip" is the same as "papAYAWHiP".

Each named color has an associated RGB value with it. If this RGB
value is not found in your colormap, PyNGL will find the closest color
to using a special algorithm. (I can't think of the name of it at the


> Any help is appreciated,
> Derrick
> --
> Derrick Snowden
> 4301 Rickenbacker Causeway
> Miami, FL 33149
> Office: 305.361.4322 Fax: 305.361.4392
> _______________________________________________
> pyngl-talk mailing list

Mary Haley         
NCAR/SCD/VETS                303-497-1254 (voice)
1850 Table Mesa Dr           303-497-1804 (fax)
Boulder, CO  80305
pyngl-talk mailing list
Received on Thu Oct 21 2004 - 09:03:09 MDT

This archive was generated by hypermail 2.2.0 : Thu Jan 19 2006 - 21:30:16 MST