Re: Urgent HELP: Unwanted color shows in color map

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Thu Nov 29 2012 - 15:44:29 MST

If I am understanding your email, you have created some code that
automatically takes the ncl-derived cnLevels from a sample plot and
develops and sets cnFillColors accordingly, trying to color the first
negative area around 0 white..

Running a variation of your script I see 2 issues, one major and one
(seemingly) minor.

Minor issue: You are setting cnLevels, but also setting
res@cnLevelSelectionMode = "ManualLevels".. The latter should be set to
"ExplicitLevels" if you are setting cnLevels.

Major issue: You are setting the same number of contour levels as you
are fill colors. The number of fill colors needs to be one more than the
number of contour levels. (For example, if you have two contours set at
-1 and 1, you will need to set 3 fill colors, one for less than -1, one
for areas greater than/equal to -1 and less than 1, and one for areas
greater than/equal to 1. )

Change these lines:
colors = new(nlevels-1,integer)
.....
num_pos = nlevels-num_neg-1
to this:
colors = new(nlevels,integer)
.....
num_pos = nlevels-num_neg

Note that now you are setting up your colors array based on nlevels, and
your cnLevels array (levv) based on nlevels-1.

Once I made that change your coding worked as I think you wanted..
Good luck,
Adam

res@cnLevels= levv
res@cnFillColors= colors

On 11/29/2012 06:13 AM, Yemi! wrote:
> Hello Everybody,
>
> I have been trying to work around this problem for some days and I
> will really appreciate any help I can get.
>
> In my code(see below), I want to be able to specify the fill colors
> myself by defining the res@cnFillColors, so I retrieved the cnLevels
> and use it to redefined the res@cnFillColors. What happened is that
> during this process, an extra color is added to the top of the
> color-table which I did not specify(and dont want either). I just want
> to define different color for negative and positive so that zero
> contour can be white.
>
> How can I get rid of this? Please help, it's urgent
>
> See part of the code and example plot attached.
>
> begin
> .....
> ..
> wks = gsn_open_wks ("pdf", "anom")
> gsn_define_colormap(wks,"ViBlGrWhYeOrRe") ;choose color map
> res = True ; plot mods desired
> res@gsnFrame = False
> res@gsnDraw = False
>
> res@cnFillOn = True ; turn on color for
> contours
> res@cnLinesOn = False ; turn off contour lines
> res@cnLineLabelsOn = False ; turn off contour
> line labels
> res@gsnAddCyclic = False
>
> i = NhlNewColor(wks,0.7,0.7,0.7) ; add gray to colormap
> res@mpLandFillColor = "gray" ; set land to be gray
> res@mpFillOn = True ; turn off gray map
> res@mpOutlineDrawOrder = "PostDraw" ; draw outline
> first
> res@mpGeophysicalLineThicknessF = 2.0
>
> res@mpMinLonF = areaw ; select a subregion
> res@mpMaxLonF = areae
> res@mpMinLatF = areas
> res@mpMaxLatF = arean
>
> res@lbOrientation = "Vertical" ; vertical label bar
> res@pmLabelBarOrthogonalPosF = -0.01 ; move label bar closer
> res@lbLabelStride = 4
>
> plot = gsn_csm_contour_map_ce(wks,varr,res) ; create plot
> getvalues plot@contour
> "cnMinLevelValF" : res@cnMinLevelValF
> "cnMaxLevelValF" : res@cnMaxLevelValF
> "cnLevelSpacingF" : res@cnLevelSpacingF
> "cnLevels" : levels
> end getvalues
> res@cnLevelSelectionMode = "ManualLevels"
> res@cnLevelSpacingF = (res@cnLevelSpacingF)/2.0
> ;---Create array containing fill indexes.
> nlevels = dimsizes(levels)*2
> colors = new(nlevels-1,integer)
> levv = fspan(levels(0),levels(dimsizes(levels)-1),nlevels-1)
> ii = ind(levv.ge.0)
> num_neg = ii(0)
> num_pos = nlevels-num_neg-1
> colors(0:num_neg-1) = toint(fspan(2,44,num_neg))
> colors(num_neg:) = toint(fspan(56,101,num_pos))
>
> res@cnLevels= levv
> res@cnFillColors= colors
>
> plot(0) = gsn_csm_contour_map_ce(wks,varr,res) ; create plot
>
> ......
> ...
> end
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk

-- 
______________________________________________________________
Adam Phillips                                asphilli@ucar.edu
NCAR/Climate and Global Dynamics Division       (303) 497-1726
P.O. Box 3000				
Boulder, CO 80307-3000    http://www.cgd.ucar.edu/cas/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Nov 29 15:44:37 2012

This archive was generated by hypermail 2.1.8 : Fri Dec 07 2012 - 13:30:06 MST