If you're not sure what GnuPlot is, here's a quick introduction, courtesy of gnuplot.info:
Gnuplot is a portable command-line driven interactive data and function plotting utility for UNIX, IBM OS/2, MS Windows, DOS, Macintosh, VMS, Atari and many other platforms.
Gnuplot supports many types of plots in either 2D and 3D. It can draw using lines, points, boxes, contours, vector fields, surfaces, and various associated text. It also supports various specialized plot types.
Basically, it's a pretty useful utility for plotting data - great! Now let's get on with how you use it.
First things first. Lets find out if GnuPlot is installed on your system. If you are running windows or OS X then, unless you have installed it, it won't be there. On linux, depending upon your system, you may or may not have it - run the following at the command-line to see if you have it (as always - ignore the numbers, they are just there to indicate line numbering):
If you have GnuPlot installed you will see somthing like this:
Version 4.0 patchlevel 0
last modified Thu Apr 15 14:44:22 CEST 2004
System: Linux 2.6.16.27-0.6-smp
Copyright (C) 1986 - 1993, 1998, 2004
Thomas Williams, Colin Kelley and many others
This is gnuplot version 4.0. Please refer to the documentation
for command syntax changes. The old syntax will be accepted
throughout the 4.0 series, but all save files use the new syntax.
Type `help` to access the on-line reference manual.
The gnuplot FAQ is available from
http://www.gnuplot.info/faq/
Send comments and requests for help to
<gnuplot-info@lists.sourceforge.net>
Send bugs, suggestions and mods to
<gnuplot-bugs@lists.sourceforge.net>
Terminal type set to 'x11'
Windows/Mac OS X
If you are running Windows use the cygwin package located here.
If you are running Mac OS X get GnuPlot here.
Linux
If your version of linux does not come with GnuPlot then you can get it here. The alternative is to use your distributions update tool. In my case (SuSe 10.1) I can use yast or apt.
Using Yast (yet another setup tool):
- Open a terminal
- Get r00t (type su)
- Type yast
- Select Software Management - this might take a few minutes
- Search for gnuplot
- Mark gnuplot-debuginfo and gnuplot for install
- Exit yast (and root), then type gnuplot
Using APT:
- Open a terminal
- Get r00t (type su)
- Type apt-cache search gnuplot
- Type apt-get install gnuplot
- Type atp-get install gnuplot-debuginfo
- Exit root and type gnuplot
For other versions of linux check your packet managers guide... better yet - get your sys admin to do it for you!
GnuPlot
As you might have guessed, GnuPlot is command-line based. It can be used for plotting functions or even your data - if you are lucky enough to have some!

The above plot shows a simple function f(x) = 1 / (1 + exp ( 1 * x - 10 )).
The first thing we shall do is generate some basic data and generate a simple 2D plot of some x and y coordinates.
| 1 | 10 |
| 2 | 20 |
| 3 | 35 |
| 4 | 40 |
| 5 | 50 |
| 6 | 45 |
| 7 | 40 |
| 8 | 35.77 |
| 9 | 15 |
| 10 | 10 |
Copy the above data into a text file, and save the file as "plot.txt" or whatever you wish to call it. Now start GnuPlot (by typing "gnuplot" at the command-line). You should now be in the GnuPlot terminal. To create a simple plot do the following:
This should create an image similar to the one shown.

A simple plot of two dimensional data with a line.
The image you have will not have a line. It should be simple dots. When you plotted the graph you did the most basic of operations, you simply told GnuPlot to make a graph of the first two columns in the file "plot.txt". This line is identical to:
Where 1 is the x-axis and 2 is the y-axis. If the "plot.txt" file had another column (3) and we wanted to plot column 1 and 3 the statement should read:
Now that is very simple. Create some more random data and have a play!
Now using your dataset, or the one I provided type:
you should get something identical to this:
^
expecting 'lines', 'points', 'linespoints', 'dots', 'impulses',
'yerrorbars', 'xerrorbars', 'xyerrorbars', 'steps', 'fsteps',
'histeps', 'filledcurves', 'boxes', 'boxerrorbars', 'boxxyerrorbars',
'vectors', 'financebars', 'candlesticks', 'errorlines', 'xerrorlines',
'yerrorlines', 'xyerrorlines', 'pm3d'
In my plot above you can clearly see a line running between the data. This is achieved using the with "lines" command (in the above block). The type of statement is going to depend upon the type of data you want to plot, in my case mostly scatter plots, if you want to experiment with these styles have a go. If you just want to see the options at your disposal type:
gnuplot> help lines
The `lines` style connects adjacent points with straight line segments.
See also `linetype`, `linewidth`, and `linestyle`.
So you now have a graph. The thing is the graph has a key in the top right corner, no labels, no title and you have no idea how to get it onto a sheet of paper...
The Key
I like the key. I know the name of the file I have used, the dimensions and if there are several things plotted, I know which line belongs to which data. We are now presented with several choices...
- Leave the graph key alone.
- Move the graph key off the graph.
- Get rid of that thing now.
- Is simple - move to the next section.
-
This is solved very simply:
gnuplot> plot 'plot.txt' using 1:2 with lines # plot the graph
gnuplot> set key outside # tell gnuplot to move the key to the right of the graph
gnuplot> replot # like java you have to tell gnuplot to redraw the screen image -
This is even simpler:
gnuplot> unset key
gnuplot> replot




News Feed
One thing I meant to do in the first introduction was how to plot a function. I find this useful as I lack the ability to visualise a graph in my head (heap allocation error).
Like the other features I showed, plotting a function is not a complex task. Simpy given our function we type it into GnuPlot like we would in say perl:
Where x is our variable. Also plot the following functions for a laugh:
7 + log10(x)
7 - log10(x)
enjoy.