background image
2
More Advanced Plots
If you are not using LyX or you have to create more advanced plots, this section describes the
steps from Octave all the way down to typesetting the PDF.
2.1
Octave
First perform all numerical calculations in Octave (or Matlab). If you are making an ordinary
2D-plot we need one ”y-value” for each ”x-value”. gnuplot wants the data in columns where
each line corresponds to one point, like this:
100.000000
22.906142
125.000000
24.844343
160.000000
26.988542
200.000000
28.926742
250.000000
30.864943
315.000000
32.872353
Suppose we have two column vectors X and Y with our precious data. To save in a gnuplot-
friendly format, type
A = [X Y];
save -ascii "xxx.dat" A
to save the matrix A in ascii format to the file xxx.dat. It is important to create the matrix A
since Octave otherwise will save the two vectors in one column after each other – not good!
You can of course save more variables than two, and that will actually become necessary
when making more advanced plots.
2.2
gnuplot
gnuplot is actually used by Octave but I find its use quite limited. Especially it has problems with
typesetting equations. gnuplot can create L
A
TEX pictures directly or EPS pictures for insertion
into documents, but to use together with pdfTEX or X E TEX the result is not that nice. But going
via Xfig produces beautiful graphs, and text is typeset correctly with X E TEX.
To produce a fig-file we need to tell gnuplot. It can be done in interactive mode but if you
want to reuse or you need to change, the best way is to write all commands in a gnuplot-file
(hereafter named just gp-file). I begin the file with
set terminal fig monochrome textspecial
set output "xxx.fig"
which makes a monochrome output – good for printing – and the textspecial command so we
can insert L
A
TEX commands like $\sin(x)$ in our figures (but actually we need two backslashes,
like $
\\sin(x)$, since one backslash will be eaten by gnuplot, the other we save for L
A
TEX).
Writing help fig in gnuplot’s interactive mode gives the following information about the options:
set terminal fig {monochrome | color}
{landscape | portrait}
{small | big | size <xsize> <ysize>}
{metric | inches}
{pointsmax <max_points>}
{solid | dashed}
{fontsize <fsize>}
{textnormal | {textspecial texthidden textrigid}}
{{thickness|linewidth} <units>}
{depth <layer>}
{version <number>}
To get a custom size of the canvas use size <x> <y>. The default is inches so change to metric
if you want to set size in centimeters. Please, refer to the help for more information.
Next line tells gnuplot where to save the file, in this case we choose xxx.fig.
This is followed by the commands of what to plot and how to plot it. It can be as easy as
plot "xxx.dat"
2