Fitting the grid to the data