Re: Why I can not label zero line in the contour

From: Adam Phillips <asphilli_at_nyahnyahspammersnyahnyah>
Date: Thu Mar 27 2014 - 18:56:53 MDT

Hi Wenjun,
If you are setting cnLineLabelPlacementMode, then you should also set
cnLineLabelDensityF..
I would try setting res@cnLineLabelDensityF = 3.5. (Larger values = more
line labels.)
http://www.ncl.ucar.edu/Document/Graphics/Resources/cn.shtml#cnLineLabelDensityF

Finally, note that you should be setting cnLineLabelPlacementMode =
"Computed" , and not cnLineLabelPlacementMode = "computed"

If that still doesn't fix the issue, please send ncl-talk your updated
script, along with any error messages and the resulting plot.
Adam

On 3/27/14, 6:04 PM, Wen.J.Qu wrote:
> Hi, Adam,
> Thanks a lot for your suggestion.
> I added a line "res@cnLineLabelInterval
> <mailto:res@cnLineLabelInterval> = 1" to the code but it still does
> not work.
> I think there may have some line repeated, but I can not find it.
> The code is also attached and pasted as following.
> Thanks a lot if anyone can help me out of this.
> 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 <mailto: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 <mailto:res@cnFillOn> = True ; turn on color fill
> res@cnLinesOn <mailto:res@cnLinesOn> = True ; turn on contour lines
> res@cnMonoLineColor <mailto:res@cnMonoLineColor> = True ; turn on the
> drawing of contours lines in one color
> res@cnLineColor <mailto:res@cnLineColor> = "white" ; set the contour
> line color as "white"
> res@gsnContourNegLineDashPattern
> <mailto:res@gsnContourNegLineDashPattern> = 2 ; set the contour line
> pattern as "dash"
> res@gsnContourPosLineDashPattern
> <mailto:res@gsnContourPosLineDashPattern> = 11 ; set the contour line
> pattern as "dash"
> res@gsnContourLineThicknessesScale
> <mailto:res@gsnContourLineThicknessesScale> = 1.8 ; set the contour
> lines thickness
> res@gsnContourZeroLineThicknessF
> <mailto:res@gsnContourZeroLineThicknessF> = 1.8 ; set the zero contour
> line thickness
> res@cnInfoLabelOn <mailto:res@cnInfoLabelOn> = True ; turn on coutour
> information label
> res@gsnSpreadColors <mailto:res@gsnSpreadColors> = True
> res@gsnSpreadColorStart <mailto:res@gsnSpreadColorStart> = 2
> res@gsnSpreadColorEnd <mailto:res@gsnSpreadColorEnd> = 255
> res@lbOrientation <mailto:res@lbOrientation> = "vertical" ; vertical
> label bars
> res@cnFillDrawOrder <mailto:res@cnFillDrawOrder> = "Predraw"
> res@cnLineDrawOrder <mailto:res@cnLineDrawOrder> = "Predraw"
> res@cnLevelSelectionMode <mailto:res@cnLevelSelectionMode> =
> "ExplicitLevels" ; set explicit contour levels
> res@cnLevels <mailto:res@cnLevels> =
> (/-200,-150,-125,-100,-80,-60,-40,-20,0,20,40,60,80,100,125,150,200/)
> res@cnLineLabelPlacementMode <mailto: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 <mailto:res@cnLevelSelectionMode> =
> "ExplicitLevels"
> res@cnLevels <mailto:res@cnLevels> = levels
> res@cnLineLabelInterval <mailto:res@cnLineLabelInterval> = 1
> ; Control which contour lines get drawn.
> res@cnLevelFlags <mailto: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 <mailto:res@cnExplicitLineLabelsOn> = True
> res@cnLineLabelStrings <mailto:res@cnLineLabelStrings> = lbstrings
> ;--------------------------------------------------
> res@mpFillOn <mailto:res@mpFillOn> = True ; turn on gray continents
> ;res@mpCenterLonF = 180 ; Centers the plot at 180
> res@mpLimitMode <mailto:res@mpLimitMode> = "LatLon"
> ;res@mpMinLonF = 72.
> ;res@mpMaxLonF = 136.
> ;res@mpMinLatF = 17.
> ;res@mpMaxLatF = 55.
> res@mpMinLonF <mailto:res@mpMinLonF> = 70.
> res@mpMaxLonF <mailto:res@mpMaxLonF> = 140.
> res@mpMinLatF <mailto:res@mpMinLatF> = 15.
> res@mpMaxLatF <mailto:res@mpMaxLatF> = 55.
>
> ;fill_specs = (/"water","land"/)
> ;res@mpFillBoundarySets = "NoBoundaries"
> ;res@mpFillAreaSpecifiers = fill_specs
> ;res@mpSpecifiedFillColors = (/"gray","gray"/)
> res@mpAreaMaskingOn <mailto:res@mpAreaMaskingOn> = 1
> res@mpMaskAreaSpecifiers <mailto: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 <mailto:res@gsnMaximize> = True ; Maximize plot in frame.
> res@gsnFrame <mailto:res@gsnFrame> = False ; Don't advance the frame
> res@mpDataSetName <mailto:res@mpDataSetName> = "Earth..4" ; This new
> database contains
> ; divisions for other countries.
> res@mpDataBaseVersion <mailto:res@mpDataBaseVersion> = "MediumRes" ;
> Medium resolution database
> res@mpOutlineOn <mailto:res@mpOutlineOn> = True ; Turn on map outlines
> res@mpOutlineSpecifiers <mailto:res@mpOutlineSpecifiers> =
> (/"China:states","Taiwan"/) ;China:states
> res@mpGeophysicalLineThicknessF
> <mailto:res@mpGeophysicalLineThicknessF>= 2. ; double the thickness of
> geophysical boundaries
> res@mpNationalLineThicknessF <mailto:res@mpNationalLineThicknessF>= 2.
> ; double the thickness of national boundaries
> ;
> ; Zoom in on P. R. China.
> ;
> res@mpMinLatF <mailto:res@mpMinLatF> = 17.
> res@mpMaxLatF <mailto:res@mpMaxLatF> = 55.
> res@mpMinLonF <mailto:res@mpMinLonF> = 72.
> res@mpMaxLonF <mailto:res@mpMaxLonF> = 136.
> ;res@mpFillColors = (/-1,-1,nc1,-1/) ;assign light gray to land masses
> res@mpFillColors <mailto:res@mpFillColors> =
> (/"transparent","transparent","transparent","transparent"/) ;fill land
> and ocean in transparent
> res@cnInfoLabelOn <mailto: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-28
> ------------------------------------------------------------------------
> *发件人:* Adam Phillips
> *发送时间:* 2014-03-28 03:01:09
> *收件人:* Wen-Jun Qu; ncl-talk
> *抄送:*
> *主题:* Re: [ncl-talk] Why I can not label zero line in the contour
> Hi Wenjun,
> Try setting the resource cnLineLabelInterval to 1 . (The default is 2)
> http://www.ncl.ucar.edu/Document/Graphics/Resources/cn.shtml#cnLineLabelInterval
>
> If that does not fix the issue please respond to the ncl-talk email list..
> Adam
>
> On 03/27/2014 12:40 PM, Wen-Jun Qu wrote:
>>
>> 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
>
> --
> ______________________________________________________________
> 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/staff/asphilli

_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Thu Mar 27 18:57:07 2014

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