2.9 Function Fitting

It is possible to fit functional forms to data points in datafiles using the fit command. A simple example might be:In gnuplot, this example would have been written fit f(x) ..., rather than fit f() .... This syntax is supported in PyXPlot, but deprecated.

f(x) = a*x+b
fit f() 'datafile' index 1 using 2:3 via a,b

The coefficients to be varied are listed after the keyword “via”; the keywords index, every and using have the same meanings as in the plot command.The select keyword, to be introduced in Section 3.3.5 can also be used.

This is useful for producing best-fit linesAnother way of producing best-fit lines is a to use a cubic spline; more details in given in Section 3.8, and also has applications for estimating the gradients of datasets. The syntax is essentially identical to that used by gnuplot, though a few points are worth noting:

At the end of the fitting process, the best-fitting values of each parameter are output to the terminal, along with an estimate of the uncertainty in each. Additionally, the Hessian, covariance and correlation matrices are output in both human-readable and machine-readable formats, allowing a more complete assessment of the probability distribution of the parameters.