Joe's
Digital Garden

GNUPlot

Get common statistics from a list of numbers

Let's say we have a list of numbers and we want to find things like the mean, median, standard deviation, range, deviation, sum, etc.

Given a set of number: {7.5, 8, 8.75, 8.25, 10.5, 8.25, 8.5, 10.5, 8, 8.5, 7, 9.5}. We can calculate a variety of statistical outputs using gnuplot:

echo "7.5\n8\n8.75\8.25\n10.5\n8.25\n8.5\n10.5\n8\n8.5\7\9.5" | gnuplot -e
'stats "-"'

I put this into a shell function:

plot () {
    cat ${1} | gnuplot -e 'stats "-"'
}

So I can just put the contents into a text file and get the stats via plot filename.txt

Graphing a CSV File.

Plotting a two variable line graph on the terminal:

Example file saved to /tmp/data.csv

1,100
2,60
3,70
4,80
5,40

And the commands for gnuplot:

gnuplot
gnulplot> set datafile separator ','
gnuplot> plot "/tmp/data.txt` using 1:2 with lines

Display a Graph in the Terminal

gnuplot> set terminal dumb

Linked References