3.8 Datafile Interpolation: Spline Fitting

The spline command fits a spline through data from a file. 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 gnuplot acsplines plot style.