;************************************************* ; scatter_4.ncl ; ; Concepts illustrated: ; - Drawing a scatter plot with a regression line ; - Calculating the least squared regression for a one dimensional array ; - Smoothing data so that seasonal cycle is less prominent ; - Changing the markers in an XY plot ; - Changing the marker color in an XY plot ; - Changing the marker size in an XY plot ; ;************************************************* load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" begin ;************************************************ ; Create pointer to file and read in temperature. ;************************************************ fon="20110411Changdao" in= asciiread("./20110411Changdao.txt",(/24,13/),"float") ts = in(:,1) ; extract time series at 60N,90W ;************************************************ ; Smooth data so that seasonal cycle is less ; prominent. This is for demo purposes only ; so that the regression line is more sloped. ;************************************************ ts = runave(ts,20,0) ;************************************************ ; Create x and calculate the regression coefficient. ; Note regline works on one dimensional arrays. ;************************************************ x = in(:,4) rc = regline(x,ts) ;************************************************ ; Create an array to hold both the original data ; and the calculated regression line. ;************************************************ data = new ( (/2,dimsizes(ts)/), typeof(ts)) data(0,:) = ts ;y = mx+b ; m is the slope: rc returned from regline ; b is the y intercept: rc@yave attribute of rc returned from regline data(1,:) = rc*(x-rc@xave) + rc@yave ;************************************************ ; plotting parameters ;************************************************ wks = gsn_open_wks("eps",fon) ; specifies a ps plot res = True ; plot mods desired res@gsnFrame = False res@gsnMaximize = True ; maximize plot in frame res@xyMarkLineModes = (/"Markers","Lines"/) ; choose which have markers res@xyMarkers = 16 ; choose type of marker res@xyMarkerColor = "red" ; Marker color res@xyMarkerSizeF = 0.005 ; Marker size (default 0.01) res@xyDashPatterns = 1 ; solid line res@xyLineThicknesses = (/1,2/) ; set second line to 2 res@tiYAxisString = "CO(ppb)" ; axis string res@tiXAxisString = "NOy(ppb)" ; axis string res@tiMainString = fon ; title res@tmYROn = False ; no right tickmarks res@tmXTOn = False plot = gsn_csm_xy (wks,ts,data,res) ; create plot txres = True ; text mods desired txres@txFontHeightF = 0.03 ; font smaller. default big ;info = "s="+sprintf("%5.2f", m) +"; yi="+sprintf("%5.2f", b) ;gsn_text(wks,plot, info ,6500, 271.25 ,txres) frame(wks) ; now advance frame delete(wks) cmd="convert -geometry 600x800 -density 300 -trim "+fon+".eps "+fon+".png" print(cmd) system(cmd) end