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/shea_util.ncl" ; ; 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("ps","poly1j") ; Open PS file "poly1j.ps" drawNDCGrid(wks) ; Draw an NDC grid for reference. mpres = True ; Variable for map resources. mpres@gsnDraw = False ; Don't draw plot yet mpres@gsnFrame = False ; Don't advance the frame mpres@mpMinLatF = 25. ; Zoom in on United States mpres@mpMaxLatF = 50. mpres@mpMinLonF = 235. mpres@mpMaxLonF = 290. mpres@mpLandFillColor = 11 ; Yellowish mpres@tiMainString = "Ugly map" ; Main title map = gsn_csm_map(wks,mpres) ; Create plot, but don't draw it. ; ; Add a marker to the plot, using the lat/lon data space of the map. ; gsres = True ; "Graphic Style" resources gsres@gsMarkerColor = "NavyBlue" ; Marker color gsres@gsMarkerIndex = 15 ; Marker style gsres@gsMarkerSizeF = 30.0 ; Marker size gsres@gsMarkerThicknessF = 3.0 ; Marker thickness dum1 = gsn_add_polymarker(wks,map,-110,40,gsres) ; ; Add polyline to the plot, again using lat/lon data space. ; You can use the same "gsres" resource list, because the "GraphicStyle" ; resources apply to polylines, polymarkers, and polygons. ; gsres@gsLineColor = "OliveDrab" ; Line color gsres@gsLineThicknessF = 3.0 ; Line thickness dum2 = gsn_add_polyline(wks,map,(/256,270,270,256,256/), \ (/ 30, 30, 36, 36, 30/), 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" txres@txFontColor = "Brown" dum3 = gsn_add_text(wks,map,"Label near marker",-108,40,txres) draw(map) ; Drawing map will draw "added" features. ; ; To draw annotations outside the plot area, you need to use the "ndc" ; procedures. These annotations cannot be added to the plot. (Well, they ; can, but this is a complicated procedure for another day.) So, ; these procedures cause the line, marker, or polygon to be drawn right ; when you call them. ; ; Draw three markers near the bottom of the frame. Note we are ; using the same "gsres" resource list, but changing the marker ; style. ; gsres@gsMarkerIndex = 12 ; Marker style (star) xm = (/.2,.5,.8/) ; NDC X coordinates ym = (/.2,.2,.2/) ; NDC Y coordinates gsn_polymarker_ndc(wks,xm,ym,gsres) ; Draw the polymarkers ; ; Draw some text strings labeling the markers. ; st = "(" + xm + "," + ym + ")" ; Strings for labels gsn_text_ndc(wks,st,xm,ym-.05,txres) ; Draw the text strings. ; Draw a weird-shaped polygon towards top of screen. gsres@gsFillColor = "Orange" ; Polygon fill color gsres@gsEdgesOn = True ; Polygon outline on gsn_polygon_ndc(wks,(/.40,.42,.50,.46,.51,.48,.40/), \ (/.90,.93,.92,.90,.88,.87,.90/),gsres) frame(wks) ; Advance frame end