; Create vectors containing random x and y locations seed=1234567L x=randomu(seed,300)*100.0 seed=2345678L y=randomu(seed,300)*100.0 ; Create a vector of simulated measurement values ; Note the y dependence. seed=3456789L data=randomu(seed,300)*15.0+y/3.0 ; The zone endpoints are created here. The data will ; be binned into zones of width 10 x_zones=[0,10,20,30,40,50,60,70,80,90] y_zones=[0,10,20,30,40,50,60,70,80,90] ; Create the 2 dimensional array that will contain ; the average value for data that are located in ; each bin. Note that the array is filled with the IEEE ; NaN fill value bins=fltarr(10,10)+!values.f_nan ; Loop over each x and y zone. Use the results of the ; where function to calculate the mean of the data values ; located within each zone for i=0,9 do begin for j=0,9 do begin subs=where( x ge x_zones(i) and $ x lt x_zones(i)+10.0 and $ y ge y_zones(j) and $ y lt y_zones(j)+10.0, $ number_found) if (number_found gt 0) then $ bins(i,j)=total(data(subs))/number_found endfor endfor loadct,0 ; Create a shaded surface of the results. Note that ; the x and y locations are adjusted to be in the ; middle of each zone shade_surf,bins,x_zones+5.0,y_zones+5.0,$ zvalue=0,background=255,color=0,$ xtitle='X',ytitle='Y',ztitle='Bin Mean' end