;************************************************* ; NCL Graphics: leg_2.ncl ; ; Concepts illustrated: ; - Drawing a legend inside an XY plot ; - Changing the width and height of a legend ; - Adding a title to a legend ; - Changing the font size of a legend title ; - Customizing the labels in a legend ; ;************************************************ ; ; These files are loaded by default in NCL V6.2.0 and newer ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" ; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" ;************************************************ begin ;************************************************ ; read in netCDF file ;************************************************ a = addfile("$NCARG_ROOT/lib/ncarg/data/cdf/uv300.nc","r") ;************************************************ ; read in zonal winds ;************************************************ lat=a->lat nlat=dimsizes(lat) u = a->U(0,:,:) uz = dim_avg(u) v = a->V(0,:,:) vz= dim_avg(v) uz!0="lat" uz&lat=lat vz!0="lat" vz&lat=lat data=new( (/2,nlat/),float) data(0,:)=uz data(1,:)=vz ;************************************************ ; create plot ;************************************************ wks = gsn_open_wks("png","leg") ; send graphics to PNG file res = True ; plot mods desired res@pmLegendDisplayMode = "Always" ; turn on legend res@pmLegendSide = "Top" ; Change location of res@pmLegendParallelPosF = .45 ; move units right res@pmLegendOrthogonalPosF = -0.4 ; move units down res@pmLegendWidthF = 0.15 ; Change width and res@pmLegendHeightF = 0.18 ; height of legend. res@lgLabelFontHeightF = .03 ; change font height res@lgTitleOn = True ; turn on legend title res@lgTitleString = "Example" ; create legend title res@lgTitleFontHeightF = .025 ; font of legend title res@xyExplicitLegendLabels = (/"U","V"/) ; explicit labels plot=gsn_csm_xy(wks,lat,data,res) end