Skip to content

B5. Numbers on the plot ​

Goal: the plot of the run says its result: the converged value with its spread, the restart marked, the window the value comes from shaded.

gnuplot
# the numbers of the run on its plot: the converged mean of the last 20 iterations, the restart marked
stats 'run.dat' using ($1 > 100 ? $5 : 1/0) nooutput
set terminal svg size 640,380
set output 'pb05.svg'
set title sprintf('c_d = %.4f ± %.4f (the last 20 iterations, shaded)', STATS_mean, STATS_stddev)
set xlabel 'iteration'; set ylabel 'c_d'
set arrow 1 from 61, graph 0 to 61, graph 1 nohead dt 2
set label 1 'restart' at 61, graph 0.92 offset 0.5,0
set object 1 rectangle from 101, graph 0 to 120, graph 1 fc 'gray' fs solid 0.15 noborder behind
plot 'run.dat' u 1:5:6 w yerrorbars pt 7 ps 0.5 t 'c_d', STATS_mean w l dt 3 t 'mean'
pb05
open SVG ↗

Why it works ​

  • stats computes gnuplot's statistics of a column into variables, STATS_mean, STATS_stddev, ...; ($1 > 100 ? $5 : 1/0) keeps the last 20 iterations, 1/0 being undefined. nooutput keeps the report off the terminal.
  • sprintf writes them into the title, a string expression; it changes with the log under --watch.
  • An arrow from graph 0 to graph 1 spans the plot at an x value; a rectangle behind shades a range of iterations; both are in axis units, so they move with a zoom in the page.
  • A constant (STATS_mean) plotted as a function is a horizontal line over the data's x range.

Try this ​

  • fit a + b*exp(-x/c) 'run.dat' u 1:5 via a, b, c and FIT_STDFIT in the title: the value the run tends to.
  • From Fortran, the same numbers: stats(cd(101:)) (Statistics).

Pitfalls ​

  • every ::100 counts points inside each block of the file: after the restart's blank line, a block starts again at 0. Select by value, as above, when the file has blocks.
  • A mean of a quantity that still oscillates is not a converged value: shade the window you averaged over, as above, so the reader can judge.

Reference: stats, labels, arrows and objects. This is the end of path B: path D for fields, path F for the report of the run.

foresight is available under your choice of license: GPL-3.0-or-later, BSD-2-Clause, BSD-3-Clause or MIT (License).