Gnuplot
Introduction
Gnuplot is a free command line tool to generate graphs and diagrams. It perfectly fits to visualise data from experience or studies for example to use them in your papers, theses or presentations. It is available for all platforms like Linux, OSX or Windows and able to generate different formats like pdf, eps, jpg or whatever you need.
Gnuplot comes with it's own language to write scripts to generate the diagrams.
For a complete feature list, please refer to the projects website: http://www.gnuplot.info
Gnuplot is an alternative to the diagram parts of the R project. It does not provide any statistic calculation.
Quick Start
The project provides a comprehensive documentation. The intention of this quick start is to provide a quick introduction into gnuplot and some hints to generate diagrams for papers or thesis.
- Download gnuplot for your platform: http://www.gnuplot.info/download.html
- Install the software and set the gnuplot/binary/ directory in the path variable of your environment
- You should be able to open a command line and type in gnuplot, press enter and the gnuplot shell should start.
- Download the example package attached to this page and extract it in a directory. Datei:Gnuplot-example.zip
In the example package, we provide an example diagram with three curves.
Curve Example
Open a command line in the directory you extracted the example package. Then type in "gnuplot gnuplot-curves-script.gplot" and press return. There should be no output on the commandline, but a new file gnuplot-curves-script.pdf in the example directory. Open this PDF and check that it contains a diagram with the mentioned three curves.
The command you typed in started the gnuplot programm with the file gnuplot-curves-script.gplot as an input. Gnuplot scripts are text fiels and do not need to have the extension gplot, but it is a recommendation to better identify them as gnuplot script.
Open the gnuplot-curves-script.gplot in your favorite text editor and you should see something similar to the code example below.
# define the output as pdf file set terminal pdf monochrome enhanced set out 'gnuplot-curves-example.pdf' # plot the curve diagram set size 1, 1 set origin 0, 0 set title "Gnuplot Diagram Example" set xlabel "Load Level" set ylabel "Utilisation [%]" set yrange [0:50] set pointsize 1 set grid set key left plot "gnuplot-curves-data.txt" using 1:2 title "System1" with linespoints pointtype 2, '' using 1:3 title "System2" with linespoints pointtype 8, '' using 1:4 title "System3" with linespoints pointtype 7 # remove all customization reset
A gnuplot script consists of a couple of settings and the call of one or more operations to generate the diagram(s). Furthermore, comments can be identified with a # character.
The first section is to specify the output you would like to generate. The second section describes the diagram to generate and the last one just resets the gnuplot shell.
The most important settings are the lables (title, xlabel and ylabel) and the yrange. While the labels are obvious, the yrange sets the part of the y axis to be displayed. In this case, only the section from 0 to 50 on the y axis will be visible.
"plot" is the function to generate the diagram. The parameters of the function are the three curves separated with a comms. The first chunk of each parameter is the file to load the data from. In this case, the empty quotes of the second and third curve are a short cut to use the same data file as for the first curve. The second chunk (i.e. 1:2) describes the data to be used for this curve. 1 means to start with the first record set while 2 identifies the second column to be used. If you take a look at the data file (gnuplot-curves-data.txt) you will notice, that the first line in this file is ignored because of the leading #, and there are multiple columns seperated by a tab. Tabs are one of the default column separators in gnuplot. The remaining chunks for the curves are their titles to be displayed in the legend and the formatting to be used. "linesploints" means to draw a line for each curve and mark the measurement points with a symbol. "pointtype 2" identifies to use the point type 2 for this curve.
Note: If you want to see all available formatting types, like for the point types, open a command line, start the gnuplot shell by entering "gnuplot" and press return. In the gnuplot shell just type in test and press return again. This will open a new window with some formatting examples.
Diagram Organisation
If you work on a paper or somewithing else with multiple diagrams, it is a good practice to write a separate gnuplot script for every diagram and an additional batch script to execute all the gnuplot scripts. This will ease up your process. For example, you would not need to open your command line again and again but can simply doubleclick this batch script.
On a windows operating system, such a batch script could look like:
gnuplot gnuplot-diagram-1-script.gplot gnuplot gnuplot-diagram-2-script.gplot gnuplot gnuplot-diagram-3-script.gplot