Incremental plotting in Gnuplot

By Mayank Lahiri. Released into the public domain.
May 12, 2009

Gnuplot is an incredibly useful command-line plotting program for Windows and Unix-like systems. However, one thing it does not do out-of-the-box (as of now) is incremental plotting -- that is, plotting a data file every n seconds while the data file is being updated. With incremental plotting, you too can have Hollywood-like displays of the output of your programs as it is being generated. It's also very useful in some situations.

This tiny, 13 line Perl script will let you do incremental plots: incplot


incplot <seconds between updates>
The script reads Gnuplot commands from standard input and pipes them to Gnuplot every n seconds, where n is the optional command line argument. If you type in Gnuplot commands from the terminal, remember to hit CTRL+D when you're done, and the incremental plotting will start. Alternatively, you could pipe in an existing Gnuplot script like this:
incplot 5 < script.gnu
This will pipe the contents of script.gnu to Gnuplot every 5 seconds, causing your display to update very 5 seconds. When you're done watching the plots change, hit CTRL+C to kill the incremental plotting process.

Standard usage

Start the program that does the number crunching, redirect its output to a file and background the process with an ampersand at the end of the command line. Then start incplot and enter the Gnuplot commands that you would normally use to plot the output of the number crunching program. Hit CTRL+D and the incremental plotting starts. Hit CTRL+C and the incremental plotting stops.

Create snapshots of progress

In your Gnuplot script, the special token '$COUNT' is replaced by the current plot iteration. You can use this to set the title to the current iteration, or to create a series of snapshots using Gnuplot's set output command (by incorporating $COUNT in the filename). Then you can stitch the snapshots together into an animated GIF or something similar.