smooth

From: Michael Notaro <mnotaro_at_nyahnyahspammersnyahnyah>
Date: Wed, 24 May 2006 14:45:13 -0500

This is a crude approach to producing a curve fit to a scatter plot.
You compute the average within different bins and then connect
those values into a curve.

Mike

load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"

begin
x=(/10.,30.,15.,40.,18.,22.,5.,9.,48.,40.,19.,11./)
y=(/3.,8.,6.,9.,0.,7.,1.,4.,8.,9.,6.,3./)

linex=(/15.,25.,35.,45./)

liney=new((/4/),float)
cnt=new((/4/),float)
liney@_FillValue=1e+35
liney=0.
cnt=0.

do i=0,3
    do j=0,11
      if ( (x(j).ge.linex(i)-5.) .and. (x(j).le.linex(i)+5.) ) then
        cnt(i)=cnt(i)+1.
        liney(i)=liney(i)+y(j)
      end if
    end do
    if (cnt(i).gt.0.) then
      liney(i)=liney(i)/cnt(i)
    else
      liney(i)=1e+35
    end if
end do

; 10-20, 20-30, 30-40, 40-50 at 15, 25, 35, 45

wks = gsn_open_wks ("ps","scatter") ; open workstation
res = True ; plot mods desired
res@gsnDraw = False
res@gsnFrame = False
res@xyMarkLineModes = "Markers"
res@trXMinF = 10.
res@trXMaxF = 50.
res@trYMinF = 0.
res@trYMaxF = 9.
plot = gsn_csm_xy (wks,x,y,res)

   polyres = True
   polyres@gsLineThicknessF = 3.0
   polyres@gsLineColor = "blue"
   polyres@trXMinF = 10.
   polyres@trXMaxF = 50.
   polyres@trYMinF = 0.
   polyres@trYMaxF = 9.
   plot1 = gsn_add_polyline (wks,plot,linex,liney,polyres)

   pres = True ; mod panel plot
   pres@gsnDraw=True
   pres@gsnFrame=True
   pres@gsnMaximize = True ; blow up plot
   pres@gsnPaperWidth=8.5
   pres@gsnPaperHeight=11.0
   pres@gsnPaperOrientation="portrait"
   pres@gsnPaperMargin=0.1
   pres@gsnPanelLeft = 0.02
   pres@gsnPanelRight = 0.98
   pres@gsnPanelBottom = 0.02
   pres@gsnPanelTop = 0.98
   pres@gsnPanelRowSpec=True
   gsn_panel(wks,plot,(/1/),pres) ; create panel plot

_______________________________________________
ncl-talk mailing list
ncl-talk_at_ucar.edu
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed May 24 2006 - 13:45:13 MDT

This archive was generated by hypermail 2.2.0 : Wed May 24 2006 - 14:35:09 MDT