2.5 2.6 3.4 3.2 2.7 2.8 5.7 5.8 4.2 4.4 8.1 8.0 1.2 1.3 7.3 7.2 6.6 6.7 9.2 9.3 10.4 10.5 11.3 11.2 12.5 12.3 13.2 13.0 10.2 10.0 14.2 14.1 15.0 14.9 16.6 16.3 17.2 17.1 18.9 19.0 4.7 5.6 5.9 6.1 3.2 5.2 7.3 4.5 19.2 20 19.5 20.5 20.3 18.9 2.3 3.2 4.9 3.4 5.9 6.7 两列数,如果横坐标取步长的中间值,纵坐标取步长范围内所有点的平均值,按第一列分组,则第一列为横坐标,按第二列分组,则第二列为横坐标 pro changablestep st='' datapath='' plotpath='' read,datapath,prompt='请输入数据路径,例如F:\data.dat' read,st,prompt='按第一列分组请输入:one,按第二列分组请输入:two ' read,step,prompt='请输入步长:' read,plotpath,prompt='请输入图片存储路径,例如F:\image.ps' print,plotpath ;按第一列分组 if strcmp(st,'one') then begin READCOL,datapath,F='f,f',col1,col2 endif ;按第二列分组 if strcmp(st,'two') then begin READCOL,datapath,F='f,f',col2,col1 endif result1=min(col1) result2=max(col1) result3=result2-result1 r1=result3/step L=round(r1) if round(r1) ge r1 then begin L=round(r1)-1 endif i=0 x=fltarr(L+1) y=fltarr(L+1) while i le L do begin step1=result1+i*step step2=result1+(i+1)*step x =(step2+step1)/2.0 ave=0.0 m=0 k=0 n=n_elements(col1)-1 while k le n do begin if col1 ge step1 and col1 lt step2 then begin m=m+1 ave=ave+col2 endif k++ endwhile if m eq 0 then begin y =ave/(m+1) endif if m ne 0 then begin y =ave/m endif i++ endwhile n1=0 i=0 while i le L do begin if y ne 0.0 then begin n1++ endif i++ endwhile x1=fltarr(n1) y1=fltarr(n1) help,x1 n2=0 i=0 while i le L do begin if y ne 0.0 then begin x1 =x y1 =y n2++ endif i++ endwhile print,x1,y1 set_plot,'ps' device,file=plotpath coeff=linfit(x1,y1) yfit=coeff +coeff *x1 plot,x1,y1,psym=2 oplot,x1,yfit device,/close end 画出来的图