6.2 Datafile Interpolation: Spline Fitting

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

plot 'data.dat' with csplines
plot 'data.dat' with 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 also is supported in PyXPlot, though splines may also be fit through data using a new, more powerful, spline command. This has a syntax similar to that of the fit command, for example:

spline f() 'data.dat' index 1 using 2:3

In this example, 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$ co-ordinates:

spline f() 'data1.dat'
spline g() 'data2.dat'
plot f(x)-g(x)

Smoothed splines can also be produced:

spline f() 'data1.dat' 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 – and a value of $1.0$ corresponds to the default amount of smoothing applied in Gnuplot’s acsplines plot style.