[ncl-talk] gsn_add_text, text not showing up?
Adam Phillips
asphilli at ucar.edu
Thu Sep 18 09:16:32 MDT 2014
Hi Elizabeth,
I think this is just a draw order problem. According to the gsn_add_text
documentation, "The text strings will be drawn only when the plot is
drawn.". So, I think all you need to do is move these five lines above the
draw(plot_d01) call:
tres = True
tres at txFontHeightF = 0.15
dum1 = gsn_add_text(wks,plot_d01,"d01, 36 km",-65,28,tres)
dum2 = gsn_add_text(wks,plot_d01,"d02,12 km",-67,36,tres)
dum3 = gsn_add_text(wks,plot_d01,"d03, 4 km",-69,41,tres)
draw(plot_d01)
;---- set polygon line resources:
lnres = True
If that does not solve it please let ncl-talk know..
Adam
On Thu, Sep 18, 2014 at 9:12 AM, Elizabeth Burakowski <burakows at ucar.edu>
wrote:
> Hi,
>
> I am trying to use gsn_add_text to include some text on my overlaid
> contour maps. However, the text I enter does not show up in the map and I
> do not receive any errors. Any ideas why the text is not showing up?
>
> Thanks,
>
> Liz.
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>
> ;==========================================================
> ; The main code
> ;==========================================================
>
> begin
>
> ;---WRF Domains directory
> dir =
> "/glade/scratch/burakows/summer_MP8LW1SW2CLMcurrent_200811-200911/run/"
>
> wrfo_d01 = addfile(dir+"wrfout_d01_2008-11-01_00:00:00.nc","r")
> wrfo_d02 = addfile(dir+"wrfout_d02_2008-11-01_00:00:00.nc","r")
> wrfo_d03 = addfile(dir+"wrfout_d03_2008-11-01_00:00:00.nc","r")
>
> d01_LC = wrfo_d01->LU_INDEX ; read present-day land use and
> preserve metadata
> d02_LC = wrfo_d02->LU_INDEX
> d03_LC = wrfo_d03->LU_INDEX
>
> d01_LC at description = " "
> d02_LC at description = " "
> d03_LC at description = " "
>
> d01_LC at lat2d = wrfo_d01->XLAT(0,:,:) ; Assign lat to x
> d01_LC at lon2d = wrfo_d01->XLONG(0,:,:) ; Assign lon
> to x
> d01_lat2d = wrfo_d01->XLAT(0,:,:)
> d01_lon2d = wrfo_d01->XLONG(0,:,:)
> dims_d01 = dimsizes(d01_LC(0,:,:))
> nlat_d01 = dims_d01(0)
> nlon_d01 = dims_d01(1)
>
> d02_LC at lat2d = wrfo_d02->XLAT(0,:,:)
> d02_LC at lon2d = wrfo_d02->XLONG(0,:,:)
> d02_lat2d = wrfo_d02->XLAT(0,:,:)
> d02_lon2d = wrfo_d02->XLONG(0,:,:)
> dims_d02 = dimsizes(d02_LC(0,:,:))
> nlat_d02 = dims_d02(0)
> nlon_d02 = dims_d02(1)
> d03_LC at lat2d = wrfo_d03->XLAT(0,:,:)
> d03_LC at lon2d = wrfo_d03->XLONG(0,:,:)
> d03_lat2d = wrfo_d03->XLAT(0,:,:)
> d03_lon2d = wrfo_d03->XLONG(0,:,:)
> dims_d03 = dimsizes(d03_LC(0,:,:))
> nlat_d03 = dims_d03(0)
> nlon_d03 = dims_d03(1)
>
> ;--- Define land use (LU_Index) categories for USGS 24 cat
>
> info = (/ \ ; USGS 24 cat
> " 1 Urban & Built-Up" ,\ ; red
> " 2 Dryland Crop & Pasture" ,\ ; lightgoldenrod1
> " 3 Irr. Crop & Pasture" ,\ ; goldenrod1
> " 4 Mix Dry/Irr Crop & Pasture" ,\ ; orange
> " 5 Crop/Grass Mosaic" ,\ ; tan2
> " 6 Crop/Wood Mosaic" ,\ ; tan4 (too dark)
> " 7 Grassland" ,\ ; khaki1
> " 8 Shrubland" ,\ ; khaki3
> " 9 Mix Shrub/Grass" ,\ ; bisque
> " 10 Savanna" ,\ ; palegoldenrod
> " 11 Decid. Broadleaf" ,\ ; palegreen
> " 12 Decid. Needleleaf" ,\ ; olivedrab3
> " 13 Evergreen Broadleaf" ,\ ; chartruese
> " 14 Evergreen Needleleaf" ,\ ; darkgreen
> " 15 Mixed Forest" ,\ ; seagreen4
> " 16 Water Bodies" ,\ ; slategray
> " 17 Herbaceous Wetland" ,\ ; mediumturquoise
> " 18 Wooden Wetland" ,\ ; midnightblue
> " 19 Barren/Sparse" ,\ ; moccasin
> " 20 Herbaceous Tundra" ,\ ; magenta
> " 21 Wooded Tundra" ,\ ; mediumorchid4
> " 22 Mixed Tundra" ,\ ; maroon4
> " 23 Bare Ground Tundra" ,\ ; mediumpurple
> " 24 Snow or Ice" /) ; white
>
>
> ninfo = dimsizes(info) ; # of categories
>
> ;----------------------------------------------------------------------
> ; Plotting options section
> ;----------------------------------------------------------------------
> pltType = "ps" ; plot type
> pltDir = "./" ; plot directory
> pltName = "DomainMap" ; plot name (ps file)
> pltPath = pltDir+pltName ; plot path
>
> colorscheme =
> (/"red","lightgoldenrod1","goldenrod1","orange","tan2","tan4",\
>
> "khaki1","khaki3","bisque","palegoldenrod","palegreen","olivedrab3",\
>
> "chartreuse","darkgreen","seagreen4","slategray1","mediumturquoise","midnightblue",\
> "moccasin","magenta","mediumorchid4","maroon4",\
> "mediumpurple","white"/)
> ncolors = dimsizes(colorscheme)
> if(ninfo.ne.ncolors) then
> print("size mismatch lu cats="+ninfo+" ,ncolors="+ncolors)
> exit
> end if
>
> wks = gsn_open_wks(pltType,pltPath) ; create workstation
> for ps file
>
> cnres = True ; plot mods desired
> cnres at gsnDraw = False
> cnres at gsnFrame = False
>
> cnres at lbLabelBarOn = False ; turn on in panel plot
> cnres at cnInfoLabelOn = False
> cnres at cnFillOn = True ; color Fill
> cnres at cnFillMode = "RasterFill"
> cnres at cnLinesOn = False ; Turn off contour lines
> cnres at cnLineLabelsOn = False
> cnres at cnLevelSelectionMode = "ExplicitLevels" ; set explict contour
> levels
> cnres at cnLevels = (/2,3,4,5,6,7,8,\
> 9,10,11,12,13,14,\
> 15,16,17,18,19,20,\
> 21,22,23,24/)
> cnres at cnFillPalette = colorscheme ; distinct colors for
> categories
> cnres at gsnSpreadColors = False ; use each color
> sequentially
>
> res = cnres ; copy contour resources from first plot
> res at mpFillOn = False
> res at mpOutlineOn = True
> res at mpOutlineBoundarySets = "AllBoundaries"
> res at mpProjection = "LambertConformal"
> res at mpOutlineDrawOrder = "PostDraw" ; draw map outlines last
> res at mpDataBaseVersion = "LowRes" ; State boundaries
> res at mpGridAndLimbOn = False
> res at pmTickMarkDisplayMode = "Always" ; Turn on map tickmarks
>
> res at mpLambertParallel1F = (max(d01_lat2d)+min(d01_lat2d))*0.3
> res at mpLambertParallel2F = (max(d01_lat2d)+min(d01_lat2d))*0.7
> res at mpLambertMeridianF = -72 ;
> res at mpLimitMode = "Corners" ; required for Lambert
> Conformal
> res at mpLeftCornerLatF = d01_lat2d(0,0)
> res at mpLeftCornerLonF = d01_lon2d(0,0)
> res at mpRightCornerLatF = d01_lat2d(nlat_d01-1,nlon_d01-1)
> res at mpRightCornerLonF = d01_lon2d(nlat_d01-1,nlon_d01-1)
> res at mpPerimOn = True
> res at mpPerimLineThicknessF = 2.0
> res at mpPerimLineColor = "black"
> res at lbTitleString = " "
> res at tfDoNDCOverlay = True ; turn off transformation
>
> res at gsnLeftString = "" ; Turn off left subtitle
> res at gsnRightString = "" ; Turn off right
> subtitle
>
> res at gsnAddCyclic = False ; regional grid
>
> res2 = cnres
> res2 at lbLabelBarOn = False ; Labelbar already created in 1st plot
> res2 at gsnMaximize = False ; Use maximization from original plot
> res3 = cnres
> res3 at lbLabelBarOn = False ; Labelbar already created in 1st plot
> res3 at gsnMaximize = False ; Use maximization from original plot
>
> ;---- Plot three domains and their land cover
>
> plot_d01 = gsn_csm_contour_map(wks,d01_LC(0,:,:),res) ; create
> plot of d01 present-day land cover
> plot_d02 = gsn_csm_contour(wks,d02_LC(0,:,:),res2) ; create plot of d02
> present-day land cover
> plot_d03 = gsn_csm_contour(wks,d03_LC(0,:,:),res3) ; create plot of d03
> present-day land cover
>
> overlay(plot_d01,plot_d02)
> overlay(plot_d01,plot_d03)
>
> draw(plot_d01)
> ;---- set polygon line resources:
> lnres = True
> lnres at gsLineColor = "black"
> lnres at gsLineThicknessF = 2.0
> gsn_polyline(wks,plot_d01,d02_lon2d(:,0),d02_lat2d(:,0),lnres)
>
> gsn_polyline(wks,plot_d01,d02_lon2d(:,nlon_d02-1),d02_lat2d(:,nlon_d02-1),lnres)
> gsn_polyline(wks,plot_d01,d02_lon2d(0,:),d02_lat2d(0,:),lnres)
>
> gsn_polyline(wks,plot_d01,d02_lon2d(nlat_d02-1,:),d02_lat2d(nlat_d02-1,:),lnres)
> gsn_polyline(wks,plot_d01,d03_lon2d(:,0),d03_lat2d(:,0),lnres)
>
> gsn_polyline(wks,plot_d01,d03_lon2d(:,nlon_d03-1),d03_lat2d(:,nlon_d03-1),lnres)
> gsn_polyline(wks,plot_d01,d03_lon2d(0,:),d03_lat2d(0,:),lnres)
>
> gsn_polyline(wks,plot_d01,d03_lon2d(nlat_d03-1,:),d03_lat2d(nlat_d03-1,:),lnres)
> tres = True
> tres at txFontHeightF = 0.15
> dum1 = gsn_add_text(wks,plot_d01,"d01, 36 km",-65,28,tres)
> dum2 = gsn_add_text(wks,plot_d01,"d02,12 km",-67,36,tres)
> dum3 = gsn_add_text(wks,plot_d01,"d03, 4 km",-69,41,tres)
>
>
> frame(wks)
>
> end
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
--
Adam Phillips
Associate Scientist, Climate and Global Dynamics Division, NCAR
www.cgd.ucar.edu/staff/asphilli/ 303-497-1726
<http://www.cgd.ucar.edu/staff/asphilli>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140918/0c3114dd/attachment.html
More information about the ncl-talk
mailing list