GNUplot Demonstration Page

Wenton L. Davis

GNUplot is a free plotting program that can be downloaded from for linux or Windoze.  Currently, linux version is 4.6.1 and Windoze is 4.6.0. On this page, you'll also see a reference to a book that can be bought:
Gnuplot Book Cover   Now available: A book on gnuplot!
Gnuplot in Action
Understanding Data with Graphs

by Philipp K. Janert
Manning Publications (2009)
ISBN: 1933988398
ISBN-13: 978-1933988399

This book is a WONDERFUL reference for using gnuplot, and has a lot of examples, including a section of gloss color pages in the middle.  There are a few examples where you have to search through the book to find code the author discusses earlier in the book, but that's my only real issue with this book.

A First Glance

Yet another command-line driven tool, the user has a lot of commands that need to be learned.  Fortunately, gnuplot has a very good help structure, strangely similar to the VAX help system; type help to get a list of top-level commands, type one of those commands to get a brief introduction, then select from a list of subcommands or options.  This is not very un*x-like, but OK, fine.

So, suppose you want to plot a simple cosine function, magnitude of 3, frequency of 4Hz:

gnuplot>plot 3*cos(2*pi*4*x)

Notice that 'pi' has kindly been predefined, so we get the output:

Ugh! It's there, but boy, does it need help.  We see that gnuplot defaulted so that the range on the X-axis was from -10 to 10, and it auto-scaled the plot, but the auto-scaling caused the plot to trample the legend, where it displays the function and line type.  Even more obvious is how the plot only drew a sampling of points.  A bit more obscure, wasn't that supposed to be 4Hz? Looks like it missed a few points! Never fear, let's use the xrange, yrange, samples, xlabel, and ylabel settings and try again:

gnuplot> set xrange [-pi:pi]
gnuplot> set yrange [-3.5:3.5]
gnuplot> set samples 1000
gnuplot> set xlabel 'X (seconds)'
gnuplot> set ylabel 'Y=f(X)'
gnuplot> replot

Ahh... much better! We can actually see the 4Hz signal, and the labels help clarify things.  The legend is readable, which is nice.  and if you look in the lower-left corner, you'll notice a coordinate.  Gnuplot's output will track the mouse movements and show the location of the cursor (mouse) in the plot.  This allows the user to locate important locations on the graph! Bonus!

So, you've collected some data, and it needs to be plotted.  An example might be the output of a gnucap simulation as seen in my gnucap_demo page:

.TITLE Lab 5 
#Time       V(1)       V(2)       V(3)      
50.E-06       0.80902    0.4542     0.46065   
51.E-06       0.74174    0.42064    0.42672   
52.E-06       0.66601    0.38249    0.38824   
53.E-06       0.58269    0.34017    0.34563

As you can see, there are four columns; the first is a time reference, and the others are voltages at nodes 1, 2, and 3.  If this file is named "lab5.out," then I can use gnuplot to show all the data:

gnuplot> set yrange [-1:1.5]
gnuplot> plot 'lab5.out' using 1:2 with lines, 'lab5.out' using 1:3 with lines, 'lab5.out' using 1:4 with lines

Well... the green line (column 3) was almost exactly the same as the blue line (column 4), so you have to look very closely at the bottom of the waves, and you'll see them.

Now that you have collected your data or found your equation and plotted them, you might want to save them directly to a file.  This is accomplished by telling gnuplot what type of file, how big, and a file name to put the image in:

gnuplot> set terminal png size 1280,1024
gnuplot> set output 'lab5.png'
gnuplot> replot

The first command tells gnuplot to generate a PNG-formatted file as a 1280x1024 image.  This is followed a command that tells gnuplot to write the image into a file named "lab5.png."  The replot command simply tells gnuplot to repeat the last plot command, but this time, the output will be in the lab5.png file instead of the screen.  Now for the gotcha: gnuplot has not yet closed the file, so it can continue to write to it.  Since in reality, you are probably done with this specific file, you type:

gnuplot> set terminal X11

and the file will close and you can continue with your next plot.

These are just some basic commands to get you started.  You can search the internet for more about gnuplot.  It really does a LOT more than I've posted here.


If you need to reach me, you can always email me at email (

revised Dec 13, 2012: add info about gnuplot