Re: The Colormap of the example polar_7

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 28 2011 - 08:44:13 MDT

Dear Lou,

NCL does not pick vector or contour levels based on the number of colors in your color map.

Rather, it looks at the range of your data and tries to pick "nice" levels giving you about 10-16 levels. It then goes through the colormap and assigns colors to each level, based on an even spacing through the color map (in this example, anyway).

If you want the color bar to contain exactly the number of colors as the range of your color map, then you will need to know how many colors are in your color map, and set the number of levels equal to this number minus 1.

For example, in the polar_7.ncl code, you would do something like this:

. . .
  gsn_define_colormap(wks,"gui_default") ; choose colormap
  i = NhlNewColor(wks,0.7,0.7,0.7) ; add gray to colormap
;---Get number of colors in color map
  getvalues wks
    "wkColorMapLen" : cmaplen
  end getvalues

;---Don't want to use first two or last two colors
  nlevels = (cmaplen-4)-1 ; One fewer levels than colors
  levels = fspan(1,15,nlevels)

. . .
  res@vcLevelSelectionMode = "ExplicitLevels"
  res@vcLevels = levels
  res@lbLabelAutoStride = True
;
; The default will be to start at color 2, and go one by one through the
; color map until you run out of colors, so we don't need these three
; resources.
; res@gsnSpreadColors = True ; use full colormap
; res@gsnSpreadColorStart = 2
; res@gsnSpreadColorEnd = -3

Note that doing this way causes you to have vector levels with values like 1.737, 2.474, 3.211, etc.

Also note that I hard-coded the vector levels, because I knew the approximate minimum/maximum of the data.
It is better to calculate this information rather than hard-code it.

--Mary

On Mar 28, 2011, at 12:24 AM, 娄一凡 wrote:

> The colormap of polar_7 is "gui_default“.
> It contains 24 colors.The start of it is 2 and the end is -3.So the colormap displayed in the wks should contain 20 colors.
> While the example contains only 16 colors,can you tell me the reason?
> I'm a greenhand at ncl and want get more help from you.<330.gif>
>
> --
> Lou Yifan
> Tsinghua University
> Department of Computer Science and Technology
> 86-15710059560
>
>
>
> <polar_7_lg.png><polar_7.ncl>_______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Mon Mar 28 08:44:19 2011

This archive was generated by hypermail 2.1.8 : Mon Mar 28 2011 - 08:51:50 MDT