Gnuplot
In the exercises we have to plot data frequently. This can be done
with the programm gnuplot
.
The program can be started from a linux console window with
gnuplot
.
There are also Windows variants. If you want to visualize your data with
you just have to write the data of your program into a file
(or on the display and then redirect).
First Steps
To make a first plot, you can start doing the following (after you have started gnuplot by command see above):
plot sin(x) title "sin(x)"
replot cos(x)
set grid
set logscale x
set xlabel "x"
set ylabel "f(x)"
set title "Plots von sinus und cosinus"
set xrange [-pi:pi]
set key
replot
unset logscale x
replot
Here are the most important commands. For all commands there is help in the
gnuplot command line:
help grid
help logscale
Plotting into files
Shall a plot e.g. be exported into an file with eps format, you can do this as following (furthermore in the gnuplot command line):
set grid
set xlabel "x"
set ylabel "f(x)"
set title "Plot des sinus"
set xrange [-3*pi:3*pi]
set key
plot sin(x) title "sin(x)"
set terminal postscript enhanced color
set out "sinus.eps"
replot
set terminal x11
The eps file is created in the current working directory.
Instead of eps files you can plot other formats by choosing the
appropriate terminal (e.g. set term png). With set term x11
change to display output again. All terminals have different
options, that influence the plot. Further information with
build-in command: help terminal.
Plotting of data files
Data files consist of several columns. Assume we have measured for a calculation its problem size, time and speed. Then the data file can look as follows:
// Commment in data file. Gnuplot knowns about comments by setting
// of set datafile commentschars "//".
//
// N t v
1 0.001 1090
10 0.02 1088
50 0.035 1023
100 0.12 789
500 0.23 560
1000 2.38 452
10000 16.76 445
Now you can choose within gnuplot, which column should be plotted.
Example:
set datafile commentschar "//"
set grid
set xlabel "N [Byte]"
set ylabel "t [ms]"
set title "Zeit-N Plot"
set key
plot "test.dat" using 2:1 with linepoints lw 3 ps 2
set terminal postscript enhanced color
set out "t-N.eps"
replot
set terminal x11
set title "Geschwindigkeit-N Plot"
set ylabel "v [MFLOP/s]"
plot "test.dat" using 3:1 with lines lw 3 ps 2
set terminal postscript enhanced color
set out "v-N.eps"
replot
Here would be plotted two eps files with time-N and speed-N diagram.
The axes are choosen automatically.