If you aren't using gnuplot, you should check it out. For those that do, I just figured out a fun tidbit on how to print fit errors that I couldn't find on the Intarwebs for the life of me.
The "fit" command in gnuplot works much like the "plot" command; you give it a data file and a "using" specification, and also the function you want to fit with and its parameters like so:
f(x) = a*x + b
a = -0.01
b = 0
fit f(x) 'somefile.txt' using 1:2:3 via a,b
You do need to give a first guess for parameters, as you see above. The "using" specification here tells it to use the first column for x, second for y and the third for error in y (which you want to include if you can). I've had plenty of trouble in the past getting a fit to converge, but generally you need to keep playing with your initial parameters and things will work out. Once the fit is done you get something like this:
After 4 iterations the fit converged.
final sum of squares of residuals : 8.19305
rel. change during last iteration : -6.6513e-10
degrees of freedom (FIT_NDF) : 9
rms of residuals (FIT_STDFIT) = sqrt(WSSR/ndf) : 0.954117
variance of residuals (reduced chisquare) = WSSR/ndf : 0.910339
Final set of parameters Asymptotic Standard Error
======================= ==========================
a = -0.00123217 +/- 0.0002571 (20.87%)
b = 0.0347759 +/- 0.001622 (4.665%)
correlation matrix of the fit parameters:
a b
a 1.000
b -0.872 1.000
Huzzah! You get your final fit parameters with error; you get degrees of freedom and stdfit and chisquare. This is fun and all, but how to I put that in my plot? First, you can get at some environment variables to use in your gnuplot script, like "FIT_WSSR" and "FIT_STDFIT." As far as the final parameters and errors, here's the best way I've found to put them on your plot:
set fit errorvariables
fit f(x) 'group_asym_out.txt' index 1 u 1:2:3 via a,b
set label sprintf("a = %2.6f +- %2.6f",a,a_err) at graph 0.7,0.15
set label sprintf("b = %2.6f +- %2.6f",b,b_err) at graph 0.7,0.1
plot 'somefile.txt' u 1:2:3 w yerr, f(x) title 'f(x)=a*x+b'
Here I've put the tricky part in bold. We have to set labels on the graph somewhere; mercifully we can use the "graph" coordinates instead of the coordinates of the plot itself, so that top right is graph (1,1) and bottom left is graph (0,0). Now we access our parameters "a" and "b" using "sprintf" in the label.
To get the errors on these parameters, we need to include "set fit errorvariables" which enables the error variables "_err," for example "a_err" and "b_err." The graph still needs some stylistic attention, but at this point it looks this:
Sources: Janert's Gnuplot in Action