Re: How to label the zero and positive labels in a contour plot?

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Mon Nov 05 2012 - 09:10:29 MST

Hi Shawn,

One way to do this is to use the cnLevelFlags resource.

See example conLab_7.ncl at:

http://www.ncl.ucar.edu/Applications/contourLab.shtml

--Mary

On Nov 3, 2012, at 11:54 PM, Wen.J.Qu wrote:

>
> Hi, all
>
> I want to label the zero and positive labels in a contour plot, but can not make it. Is it because of the use of "ExplicitLevels"?
>
> Please give me some suggestions on this. Thanks a lot.
>
> The plot and the code following.
>
>
> Shawn
>
>
> **********************************************************
> <Catch0_2012-11-04-00-54-35-62.bmp>
> **********************************************************
>
>
>
> **********************************************************
> ;************************************************
> ; create plot
> ;************************************************
> wks = gsn_open_wks("ps","summer_average_vertical_velocity_plot") ; open a ps file
> gsn_define_colormap(wks,"gui_default")
> res = True ; plot mods desired
> res@tiMainString = "summer average vertical velocity"
>
> res@cnFillOn = True ; turn on color fill
> res@cnLinesOn = True ; turn on contour lines
> res@cnMonoLineColor = True ; turn on the drawing of contours lines in one color
> res@cnLineColor = "white" ; set the contour line color as "white"
> res@gsnContourNegLineDashPattern = 2 ; set the contour line pattern as "dash"
> res@gsnContourPosLineDashPattern = 11 ; set the contour line pattern as "dash"
> res@gsnContourLineThicknessesScale = 2.0 ; set the contour lines thickness
> res@gsnContourZeroLineThicknessF = 2.0 ; set the zero contour line thickness
> ;res@cnInfoLabelOn = True ; turn on coutour information label
> res@gsnSpreadColors = True ; use full colormap
> res@lbOrientation = "vertical" ; vertical label bars
> res@cnFillDrawOrder = "Predraw"
> res@cnLineDrawOrder = "Predraw"
>
> res@cnLevelSelectionMode = "ExplicitLevels" ; set explicit contour levels
> res@cnLevels = (/-0.26,-0.24,-0.22,-0.20,-0.18,-0.16,-0.14,-0.12,-0.10,-0.08,-0.06,-0.04,-0.02,0,0.02,0.04,0.06/)
>
> res@cnLineLabelPlacementMode = "computed" ; define the contour Line Label Placement Mode
>
>
> ;--------------------------------------------------
> ;set only to label the zero and positive labels
> levels = (/-0.26,-0.24,-0.22,-0.20,-0.18,-0.16,-0.14,-0.12,-0.10,-0.08,-0.06,-0.04,-0.02,0,0.02,0.04,0.06/)
> nlev = dimsizes(levels)
>
> res@cnLevelSelectionMode = "ExplicitLevels"
> res@cnLevels = levels
>
> lbstrings = new(nlev, "string")
> lbstrings = ""
> lbstrings = where(levels .eq. 0, "0", 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 = True
> res@cnLineLabelStrings = lbstrings
> ;--------------------------------------------------
>
>
> res@mpFillOn = True ; turn on gray continents
> ;res@mpCenterLonF = 180 ; Centers the plot at 180
> res@mpLimitMode = "LatLon"
> res@mpMinLonF = 72.
> res@mpMaxLonF = 136.
> res@mpMinLatF = 17.
> res@mpMaxLatF = 55.
>
> ;fill_specs = (/"water","land"/)
> ;res@mpFillBoundarySets = "NoBoundaries"
> ;res@mpFillAreaSpecifiers = fill_specs
> ;res@mpSpecifiedFillColors = (/"gray","gray"/)
>
> res@mpAreaMaskingOn = 1
> 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 = True ; Maximize plot in frame.
> res@gsnFrame = False ; Don't advance the frame
>
> res@mpDataSetName = "Earth..4" ; This new database contains
> ; divisions for other countries.
> res@mpDataBaseVersion = "MediumRes" ; Medium resolution database
> res@mpOutlineOn = True ; Turn on map outlines
> res@mpOutlineSpecifiers = (/"China:states","Taiwan"/) ;China:states
>
> res@mpGeophysicalLineThicknessF= 2. ; double the thickness of geophysical boundaries
> res@mpNationalLineThicknessF= 2. ; double the thickness of national boundaries
> ;
> ; Zoom in on P. R. China.
> ;
> res@mpMinLatF = 17.
> res@mpMaxLatF = 55.
> res@mpMinLonF = 72.
> res@mpMaxLonF = 136.
>
> ;res@mpFillColors = (/-1,-1,nc1,-1/) ;assign light gray to land masses
> res@mpFillColors = (/"transparent","transparent","transparent","transparent"/) ;fill land and ocean in transparent
>
> res@cnInfoLabelOn = False ;Don't draw an informational label
>
> plot = gsn_csm_contour_map_ce(wks,verticalvelocity_summer_allyearaverage(:,:), res) ; create plot
> **********************************************************
>
> Wen.J.Qu
> 2012-11-04
> _______________________________________________
> 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 Nov 5 09:10:38 2012

This archive was generated by hypermail 2.1.8 : Tue Nov 06 2012 - 15:05:49 MST