Skip navigation.

Gnuplot - Generating Graph Images From The Command Line

Gnuplot - Generating Graph Images From The Command Line

Gnuplot is a free cross-platform program for scientific plotting, but is also useful for generating all sorts of other graphs.

There are lots of tutorials showing how to use Gnuplot in interactive mode.  However, Gnuplot can also be scripted from the command line for generating static images of graphs/plots.  I usually need to graph performance data, consisting of X,Y data points.  Gnuplot allows me to do this easily by passing a config file to the Gnuplot program in non-interactive mode.

Here is a sample data file (plot.data) containing x, y coordinates:

0 2
3 11
5 1
9 10
14 11
20 18
30 9

Here is a sample Gnuplot config file (plot.cfg)

set term png 

set output "plot.png"
set size 0.8,0.5
set yrange [0:]
set xlabel "Elapsed Time"
set ylabel "Throughput (requests/sec)"
plot "plot.data" using 1:2 title "" w lines

From the command line, you can run it like:

Windows:

> wgnuplot.exe plot.cfg

Unix/Linux:

$ gnuplot plot.cfg

This will create an image named "plot.png" containing the line graph:

Here is sample output of rendering a larger data set with an impulse graph and a line graph:

Now that you can run it from the CLI, it is easy to integrate with other scripts or programs.