Difference between revisions of "Tip 19: GNUplot"

From Vlsiwiki
Jump to: navigation, search
(Created page with 'GNUplot is a free plotting utility. It is one of the most flexible ones available and includes options for 3D, heat plots, animation, splines, polar, etc. It also has basic stati…')
(No difference)

Revision as of 23:20, 1 August 2011

GNUplot is a free plotting utility. It is one of the most flexible ones available and includes options for 3D, heat plots, animation, splines, polar, etc. It also has basic statistics capabilities, but it is often best to do that in another language such as Python or Perl.

This tutorial will only cover the very basics of GNUplot. For more complete examples, see the demo page: http://gnuplot.sourceforge.net/demo/ You should also make sure to look at the demos for the appropriate version. The recent versions from the last few years have had some great advances in visualization.

GNUplot is nice because it can save in very flexible formats and it is portable among Mac, PC, Linux. It also doesn't charge a license fee so you can always recreate your plots without a Matlab or Vizio or M$ license. It is most often useful to save directly as a .eps or .pdf file. These are "vector" formats which means that they can scale to any size and do not lose resolution. As opposed to a .gif or .bmp which is a bit-map image and loses resolution when scaled.

You can run gnuplot either in interactive mode or batch mode. Just typing gnuplot at the command line will start up interactive mode with a "gnuplot>" prompt. Batch mode is run by supplying a script to gnuplot with a command like "gnuplot myplot.gpl". The .gpl file contains the same commands as interactive mode.

If you do not specify the output, gnuplot will display the result on your current screen. If you want to save the output to a file, you must specify the format and the file name like this:

set terminal eps
set output "myfile.eps"

If you just type "set terminal" it will list the available output formats. (If pdf is not available, you can save as eps and then run eps2pdf.)

You can plot basic data in one of two ways. The first is with inline data such as

plot '-'
0 1
1 2
3 4
5 6
e

The hyphen tells the plot command contains the data. If you replace that with a file, it will take data from the file:

plot 'myfile.dat'

where myfile.dat contains

0 1
1 2
3 4
5 6

Note that the "e" is short for "end" and terminates a data set. You can supply more than one data set to a plot command and more than one plot command per batch file.