3.8 Datafile Interpolation: Spline Fitting

Gnuplot allows data to be interpolated using its csplines plot style, for example:

plot 'datafile' with smooth csplines
plot 'datafile' with smooth acsplines

where the upper statement fits a spline through all of the datapoints, and the lower applies some smoothing to the data first. This syntax is supported in PyXPlot but deprecated. A similar effect can be achieved with the new, more powerful, spline command. This has a syntax similar to that of the fit command, for example:

spline f() 'datafile' index 1 using 2:3

The function $ f(x)$ now becomes a special function, representing a spline fit to the given datafile. It can be plotted or otherwise used in exactly the same way as any other function. This approach is more flexible than gnuplot's syntax, as the spline $ f(x)$ can subsequently be spliced together with other functions (see the previous section), or used in any mathematical operation. The following code snippet, for example, would fit splines through two datasets, and then plot the interpolated differences between them, regardless, for example, of whether the two datasets were sampled at exactly the same $ x$ coordinates:

spline f() 'datafile1'
spline g() 'datafile2'
plot f(x)-g(x)

Smoothed splines can also be produced:

spline f() 'datafile1' smooth 1.0

where the value $ 1.0$ determines the degree of smoothing to apply; the higher the value, the more smoothing is applied. The default behaviour is not to smooth at all (equivalent to smooth 0.0); a value of $ 1.0$ corresponds to the default amount of smoothing applied in the acsplines plot style.

Dominic Ford 2006-09-09