load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl" ; ; Draws a filled box in NDC space, given a workstation, the X,Y center ; of the box, the size of the box, and a color. ; procedure draw_ndc_box(wks,xcen,ycen,size,color) local xbox, ybox, bxres begin size2 = size/2. xbox = (/xcen-size2,xcen+size2,xcen+size2,xcen-size2,xcen-size2/) ybox = (/ycen-size2,ycen-size2,ycen+size2,ycen+size2,ycen-size2/) bxres = True bxres@gsFillColor = color gsn_polygon_ndc(wks,xbox,ybox,bxres) end ; ; Draws a text string in NDC space, given a workstation, the ; string, the X,Y position of the string (left-justified), ; and the size of the string. ; procedure draw_text_str(wks,str,xleft,ycen,size) local txres begin txres = True txres@txJust = "CenterLeft" txres@txFontHeightF = size gsn_text_ndc(wks,str,xleft,ycen,txres) end ; ; The poly1* series of examples shows how to add various annotations ; to a plot, like markers, text, polygons, and lines. There are ; two different data spaces you can use for adding this stuff: NDC ; space, or data space. Both will be shown. ; begin wks = gsn_open_wks("png","poly1k") ; Open png file "poly1k.png" gsn_define_colormap(wks,"uniform") ; Color map w/lots of colors drawNDCGrid(wks) ; Draw an NDC grid for reference. mpres = True ; Plot options desired. mpres@gsnDraw = False ; Don't draw plot yet mpres@gsnFrame = False ; Don't advance the frame mpres@mpProjection = "Orthographic" mpres@mpEllipticalBoundary = True mpres@mpCenterLatF = 20.0 mpres@mpCenterLonF = 14.0 mpres@mpLimitMode = "LatLon" mpres@mpMinLatF = -40 mpres@mpMaxLatF = 42 mpres@mpMinLonF = -20 mpres@mpMaxLonF = 60 fill_areas = (/"Mali", "Egypt", "Ethiopia", "Tanzania", "Namibia", \ "Zaire", "Morocco", "Water", "Land"/) fill_colors = (/46,68,50,138,161,87,83,3,76/) mpres@mpFillAreaSpecifiers = fill_areas mpres@mpSpecifiedFillColors = fill_colors mpres@mpOutlineOn = True mpres@tiMainString = "Random countries of Africa" ; Main title map = gsn_csm_map(wks,mpres) ; Draw plot ; ; Add a marker to the plot at the position of Lake Chad, using ; the lat/lon data space of the map (lon = 14, lat = 13). ; gsres = True ; "Graphic Style" resources gsres@gsMarkerColor = "NavyBlue" ; Marker color gsres@gsMarkerIndex = 15 ; Marker style gsres@gsMarkerSizeF = 0.03 ; Marker size gsres@gsMarkerThicknessF = 3.0 ; Marker thickness dum1 = gsn_add_polymarker(wks,map,14,13,gsres) ; ; Add a text string to the plot. This time, create a new resource ; list, because text string resources are separate. ; txres = True ; Text resources txres@txFontHeightF = 0.02 ; Font height txres@txJust = "CenterLeft" ; Default is "CenterCenter" dum3 = gsn_add_text(wks,map,"Label near marker",7,17,txres) draw(map) ; If gsnDraw is False, then here's how you draw plot. ; ; Add some filled polygons outside the map area, using the NDC ; grid as a guide. ; do i=0,dimsizes(fill_colors)-3 ; Don't include water or land draw_ndc_box(wks,0.85,0.8-i*0.1,0.025,fill_colors(i)) draw_text_str(wks,fill_areas(i),0.87,0.8-i*0.1,0.02) end do frame(wks) ; If gsnFrame is False, then here's how you advance frame. end