Data Visualization with Gnuplot
Contents
Introduction
Gnuplot, which is installed on njord.hpc.ntnu.no, is a program for creating simple plots of data, such as the one seen below. This introduction to Gnuplot will show you how to create such a plot of your data.

The Data
The data that was used to produce the plot is listed below (ref).
# Force-Deflection data for a beam and a bar # Deflection Col-Force Beam-Force 0.000 0 0 0.001 104 51 0.002 202 101 0.003 298 148 0.0031 290 149 0.004 289 201 0.0041 291 209 0.005 310 250 0.010 311 260 0.020 280 240
The Program
Gnuplot can be used interactively, but in order to reuse a set of Gnuplot commands, between datasets that are being produced by simulations, you must create a file with the commands. Below is shown the program that was used to create the plot shown in the introduction:
set xr [0.0:0.021]
set yr [0:325]
set xtic auto
set ytic auto
set title "Force Deflection Data for a Beam and a Column"
set xlabel "Deflection (meters)"
set ylabel "Force (kN)"
set label "Yield Point" at 0.0046,271
set arrow from 0.0044,272 to 0.0034,285
set key 0.0185,80
set terminal png enhanced
set output "force.png"
plot "force.dat" using 1:2 title 'Column' with linespoints, \
"force.dat" using 1:3 title 'Beam' with points
This program will be explained below.
Axes
These four lines set the axes:
set xr [0.0:0.021] set yr [0:325] set xtic auto set ytic auto
The first line sets the X axis to the range from 0.0 to 0.021 and the second line sets the Y aixs to the range from 0 to 325. If you are not sure of what the range of the data is, then you should use the auto-scaling functionality, instead of these two lines:
set autoscale
In the case above, using auto-scaling would make the X-axis be cut of at 0.02 and make the Y-axis go to 350, which would make the plot look at bit less nice.
The last two lines tell Gnuplot to automatically calculate the position of the numbers on the axes. If you want another set of "tics" on one of the axes, then you can set them manually such as in:
set xtics (0.002,0.004,0.006,0.008,0.010,0.012,0.014,0.016,0.018,0.020)
Text
The next four lines set the text that is seen on the plot (except for the legend):
set title "Force Deflection Data for a Beam and a Column" set xlabel "Deflection (meters)" set ylabel "Force (kN)" set label "Yield Point" at 0.0046,271
The first line sets the title. The two next lines set the labels on the axes and the last line puts the text "Yield Point" at the specified coordinate. The coordinate uses, of course, the axes' coordinate system.
Arrow
The next line create the arrow that points to the yield point in the plot:
set arrow from 0.0044,272 to 0.0034,285
Two coordinates are specified, which both, of course, are relative to the axes in the plot.
Key
The set key command enables a key (or legend) describing the two curves the plot:
set key 0.0185,80
In this case, the key is positioned at (0.0185, 80).
Output
The next two lines specify the format of the files that is created:
set terminal png set output "force.png"
The first line specifies that Gnuplot should produce a PNG image file. There are many options that can follow the keyword "png", such as for instance {tiny | small | medium | large | giant} for specifying the font size and {size < x >,< y >} for specifying the size of the image (default is 640x480 pixels). The second line tells Gnuplot the name of the file in which the produced image should be stored.
However, there are many more supported output formats, such as for instance Postscript. If you want to produce a Postscript file, then you could e.g. replace the two lines above with:
set size 1.0, 0.6 set terminal postscript portrait enhanced color solid lw 2.0 "Helvetica" 14 set output "force.ps"
The first line tells Gnuplot to only use 60% of the vertical length of a page.
The second line tells Gnuplot to:
- use portrait mode (in contrast to "landscape" mode).
- allow subscripts, superscripts and mixed fonts (if any).
- allow colors (in contrast to "mono" mode).
- draw with solid lines, overriding any dashed patterns.
- scale all line widths with a factor of 2.0.
- use the font "Helvetica" with the font size "14".
The last line tells Gnuplot to store the Postscript in a file called "force.ps".
Plot
The plot command consists of the two lines.:
plot "force.dat" using 1:2 title 'Column' with linespoints, \
"force.dat" using 1:3 title 'Beam' with points
Notice that the first line ends with a backslash (\). Commands may extend over several input lines by ending each line but the last with a backslash. The backslash must be the last character on each line. The effect is as if the backslash and newline were not there. That is, no white space is implied, which is why there is a space right before the backslash.
The command tells Gnuplot to plot the data in the "force.dat" file twice. The first time it reads the coordinate points from the first and the second column, sets the legend entry for these points to 'Column' and uses the 'linespoints' drawing style. The second time it reads the coordinate points from the first and the third columns, sets the legend entry for these points to 'Beam' and uses the 'points' drawing style.
References
There are many more possibilities with Gnuplot than can be covered on this page. To see examples scripts and plots, look at the demo section on Gnuplot's web-site: http://www.gnuplot.info/demo/
The main source of information about Gnuplot is the documentation: http://www.gnuplot.info/documentation.html

