Why I can not label zero line in the contour

From: Wen-Jun Qu <wen.j.qu_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 27 2014 - 12:40:22 MDT

 Hello, dear NCL friends,

I am try to draw a contour and label the zero line, but I failed many times.

Would anyone pls help me to find where is the bug?

I attached the code and also paste it as following.

Thanks a lot in advance.

Wenjun

******************************************************************************************************

;************************************************
; Plot less CW winter average boundary layer height0utc6step anomaly
;************************************************

;************************************************
; create plot
;************************************************
  wks =
gsn_open_wks("ps","lesscw_winter_average_boundary_layer_height0utc6step_anomaly")
; open a ps file
  gsn_define_colormap(wks,"rainbow")
  res = True ; plot mods desired
  ;res@tiMainString = "Less CW winter average boundary layer
height0utc6step anomaly (meter) ~C~ (95% significance)"

  res@gsnAddCyclic <javascript:_e(%7B%7D,'cvml','res@gsnAddCyclic');>
= False ; The range of the longitude data is not 360, may want
to set gsnAddCyclic to False to avoid a warning
  res@cnFillOn <javascript:_e(%7B%7D,'cvml','res@cnFillOn');> =
True ; turn on color fill
  res@cnLinesOn <javascript:_e(%7B%7D,'cvml','res@cnLinesOn');>
= True ; turn on contour lines
  res@cnMonoLineColor
<javascript:_e(%7B%7D,'cvml','res@cnMonoLineColor');>
= True ; turn on the drawing of contours lines in one color
  res@cnLineColor <javascript:_e(%7B%7D,'cvml','res@cnLineColor');>
= "white" ; set the contour line color as "white"
  res@gsnContourNegLineDashPattern<javascript:_e(%7B%7D,'cvml','res@gsnContourNegLineDashPattern');>
= 2 ; set the contour line pattern as "dash"
  res@gsnContourPosLineDashPattern<javascript:_e(%7B%7D,'cvml','res@gsnContourPosLineDashPattern');>
= 11 ; set the contour line pattern as "dash"
  res@gsnContourLineThicknessesScale<javascript:_e(%7B%7D,'cvml','res@gsnContourLineThicknessesScale');>=
1.8 ; set the contour lines thickness
  res@gsnContourZeroLineThicknessF<javascript:_e(%7B%7D,'cvml','res@gsnContourZeroLineThicknessF');>
= 1.8 ; set the zero contour line thickness
  res@cnInfoLabelOn <javascript:_e(%7B%7D,'cvml','res@cnInfoLabelOn');>
= True ; turn on coutour information label
  res@gsnSpreadColors
<javascript:_e(%7B%7D,'cvml','res@gsnSpreadColors');>
= True
  res@gsnSpreadColorStart<javascript:_e(%7B%7D,'cvml','res@gsnSpreadColorStart');>
= 2
  res@gsnSpreadColorEnd<javascript:_e(%7B%7D,'cvml','res@gsnSpreadColorEnd');>
= 255
  res@lbOrientation <javascript:_e(%7B%7D,'cvml','res@lbOrientation');>
= "vertical" ; vertical label bars
  res@cnFillDrawOrder
<javascript:_e(%7B%7D,'cvml','res@cnFillDrawOrder');>
= "Predraw"
  res@cnLineDrawOrder
<javascript:_e(%7B%7D,'cvml','res@cnLineDrawOrder');>
= "Predraw"

  res@cnLevelSelectionMode<javascript:_e(%7B%7D,'cvml','res@cnLevelSelectionMode');>
= "ExplicitLevels" ; set explicit contour levels
  res@cnLevels <javascript:_e(%7B%7D,'cvml','res@cnLevels');>
= (/-200,-150,-125,-100,-80,-60,-40,-20,0,20,40,60,80,100,125,150,200/)

  res@cnLineLabelPlacementMode<javascript:_e(%7B%7D,'cvml','res@cnLineLabelPlacementMode');>=
"computed" ; define the contour Line Label Placement Mode

  levels =
(/-200,-150,-125,-100,-80,-60,-40,-20,0,20,40,60,80,100,125,150,200/)
  nlev = dimsizes(levels)

;--------------------------------------------------
  ;set only to label the zero and positive labels
  res@cnLevelSelectionMode<javascript:_e(%7B%7D,'cvml','res@cnLevelSelectionMode');>=
"ExplicitLevels"
  res@cnLevels <javascript:_e(%7B%7D,'cvml','res@cnLevels');> = levels

; Control which contour lines get drawn.
  res@cnLevelFlags <javascript:_e(%7B%7D,'cvml','res@cnLevelFlags');>
= (/"NoLine","NoLine","NoLine","NoLine",
"NoLine","NoLine","NoLine","NoLine","LineAndLabel","NoLine","NoLine","NoLine",
\
                              "NoLine","NoLine","NoLine","NoLine","NoLine"/)

  lbstrings = new(nlev, "string")
  ;lbstrings = ""
  lbstrings = where(levels .eq. 0, "0", 0)
  print(lbstrings)
  ;lbstrings = where(levels .eq. 0.02, "0.02", lbstrings)
  ;lbstrings = where(levels .eq. 0.04, "0.04", lbstrings)
  ;lbstrings = where(levels .eq. 0.06, "0.06", lbstrings)

  res@cnExplicitLineLabelsOn<javascript:_e(%7B%7D,'cvml','res@cnExplicitLineLabelsOn');>=
True
  res@cnLineLabelStrings<javascript:_e(%7B%7D,'cvml','res@cnLineLabelStrings');>=
lbstrings
;--------------------------------------------------

  res@mpFillOn <javascript:_e(%7B%7D,'cvml','res@mpFillOn');>
= True ; turn on gray continents
  ;res@mpCenterLonF = 180 ; Centers the plot at 180
  res@mpLimitMode <javascript:_e(%7B%7D,'cvml','res@mpLimitMode');>
= "LatLon"
  ;res@mpMinLonF = 72.
  ;res@mpMaxLonF = 136.
  ;res@mpMinLatF = 17.
  ;res@mpMaxLatF = 55.
  res@mpMinLonF <javascript:_e(%7B%7D,'cvml','res@mpMinLonF');>
= 70.
  res@mpMaxLonF <javascript:_e(%7B%7D,'cvml','res@mpMaxLonF');>
= 140.
  res@mpMinLatF <javascript:_e(%7B%7D,'cvml','res@mpMinLatF');>
= 15.
  res@mpMaxLatF <javascript:_e(%7B%7D,'cvml','res@mpMaxLatF');>
= 55.

  ;fill_specs = (/"water","land"/)
  ;res@mpFillBoundarySets = "NoBoundaries"
  ;res@mpFillAreaSpecifiers = fill_specs
  ;res@mpSpecifiedFillColors = (/"gray","gray"/)

  res@mpAreaMaskingOn
<javascript:_e(%7B%7D,'cvml','res@mpAreaMaskingOn');>
= 1
  res@mpMaskAreaSpecifiers<javascript:_e(%7B%7D,'cvml','res@mpMaskAreaSpecifiers');>=
(/"China","Taiwan"/)

;
; Set up some map resources.
;
  ;nc1 = NhlNewColor(wks,.7,.7,.7) ; Add light gray to colormap,
                                          ; for continents.
  res = True
  res@gsnMaximize <javascript:_e(%7B%7D,'cvml','res@gsnMaximize');> =
True ; Maximize plot in frame.
  res@gsnFrame <javascript:_e(%7B%7D,'cvml','res@gsnFrame');> =
False ; Don't advance the frame

  res@mpDataSetName <javascript:_e(%7B%7D,'cvml','res@mpDataSetName');>
= "Earth..4" ; This new database contains
                                           ; divisions for other countries.
  res@mpDataBaseVersion<javascript:_e(%7B%7D,'cvml','res@mpDataBaseVersion');>
= "MediumRes" ; Medium resolution database
  res@mpOutlineOn <javascript:_e(%7B%7D,'cvml','res@mpOutlineOn');>
= True ; Turn on map outlines
  res@mpOutlineSpecifiers<javascript:_e(%7B%7D,'cvml','res@mpOutlineSpecifiers');>
= (/"China:states","Taiwan"/) ;China:states

  res@mpGeophysicalLineThicknessF<javascript:_e(%7B%7D,'cvml','res@mpGeophysicalLineThicknessF');>=
2. ; double the thickness of geophysical boundaries
  res@mpNationalLineThicknessF<javascript:_e(%7B%7D,'cvml','res@mpNationalLineThicknessF');>=
2. ; double the thickness of national boundaries
;
; Zoom in on P. R. China.
;
  res@mpMinLatF <javascript:_e(%7B%7D,'cvml','res@mpMinLatF');> = 17.
  res@mpMaxLatF <javascript:_e(%7B%7D,'cvml','res@mpMaxLatF');> = 55.
  res@mpMinLonF <javascript:_e(%7B%7D,'cvml','res@mpMinLonF');> = 72.
  res@mpMaxLonF <javascript:_e(%7B%7D,'cvml','res@mpMaxLonF');> = 136.

  ;res@mpFillColors = (/-1,-1,nc1,-1/) ;assign light gray to land masses
  res@mpFillColors <javascript:_e(%7B%7D,'cvml','res@mpFillColors');> =
(/"transparent","transparent","transparent","transparent"/) ;fill
land and ocean in transparent

  res@cnInfoLabelOn <javascript:_e(%7B%7D,'cvml','res@cnInfoLabelOn');> =
False ;Don't
draw an informational label

  plot =
gsn_csm_contour_map_ce(wks,blh0utc6step_ave_lesscwyear_anomaly(:,:), res)
; create plot

******************************************************************************************************

 ------------------------------
 Wen.J.Qu
2014-03-27

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk

Received on Thu Mar 27 12:40:29 2014

This archive was generated by hypermail 2.1.8 : Mon Mar 31 2014 - 11:47:09 MDT