goldb.org home

AS OF MAY 2008, THIS BLOG IS NO LONGER BEING UPDATED.
Visit the new blog at: http://coreygoldberg.blogspot.com



 Monday, March 17, 2008

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.

#    Comments [3] |
Monday, March 17, 2008 5:33:53 PM (Eastern Standard Time, UTC-05:00)
I'd love to subscribe to your blog. I just prefer Feedburner via Email...
Friday, March 21, 2008 1:09:59 AM (Eastern Standard Time, UTC-05:00)
Excellent tip. I've never used GNU Plot, but obviously I need to learn it now.

You refer to two different files by the same name (plot.data). I think the first one is "plot.data" and the second one is "plot.cfg". This is nit-picky, but it threw me off at first.
Friday, March 21, 2008 7:59:25 AM (Eastern Standard Time, UTC-05:00)
@James

thanks for finding the typos. nitpicks are always welcomed!
Comments are closed.