Friday, April 24, 2009

Histograms in gnuplot

I'm pretty new to gnuplot, but have found it to be a handy tool for simple plots.  

Today I needed to generate a simple histogram.  Rather than creating a permanent script I've just been piping a string into gnuplot from echo.

echo "set terminal png;\
set output 'timings.png';\
set style fill solid 0.5 border -1;\
set xlabel 'chunks';\
set ylabel 'time to complete (m)';\
set key autotitle columnhead;\
set title 'timings on 20 nodes';\
set auto x;\
plot 'timings.tsv' u 2:xticlabels(1) with boxes lt 2;"\
|  gnuplot

and out pops a nice histogram (sorry, can't post this example as it's work related).

The input file had column headers and the first column was used as the xlabels (see the xticlabels call above?)


  1. line 0: undefined variable: columnhead

    line 0: undefined function: xticlabels

    [root@fstest gnuplot]# cat grphist.conf | gnuplot
    line 0: undefined function: xticlabels

  2. You are using an older version of gnuplot. You'll need version 4.2 or above for columnhead[er]. Also xticlabels appeared in version 4.1.