Gnuplotting

Create scientific plots using gnuplot

May 20th, 2011 | 4 Comments

The tikz and epslatex terminal directly write text in the graph by using LaTeX. But if you want a line break within a label, a simple \\ will not work. In order to get a line break we can apply the \shortstack command.

set label '\shortstack{first line\\second line}'

In the following example, a principal component analysis (PCA) for attribute ratings of a listening test has been computed and the attributes together with the presented stimuli are plotted in the graph. The natural + little comb filter attribute and its counterpart included a line break (click on the figure for a larger version).

loudspeaker circle

Fig. 1 A PCA plot with a line break in two of its attribute labels (click on the figure for a larger view, code to produce this figure)

March 31st, 2011 | 2 Comments

Beside the epslatex terminal, Gnuplot offers another terminal which can be used in companion with LaTeX. The tikz terminal creates only a tex file without any eps file. The trick is that it uses the tikz environment of LaTeX to draw the whole plot with TeX.

The downside is that this terminal is a new one and not available in the most standard installations of Gnuplot and it could be that there are a few bugs in comparison to epslatex.

In order to install the tikz terminal we have to compile Gnuplot by ourself with the lua flag enabled and install it the usual way:

$ ./configure --with-lua=yes
$ make
# make install

To do so we have to install lua before of course. Under Debian and Ubuntu we have to fix also two links in order to find the lua package:

# ln -s /usr/lib/pkgconfig/lua5.1.pc  /usr/lib/pkgconfig/lua.pc
# ln -s /usr/lib/liblua5.1.so  /usr/lib/liblua.so

If the installation is complete, we can use the tikz terminal in the normal way

set teminal tikz

For lots of plots in our LaTeX document we can get a problem with the TeX memory. In order to fix this use more memory for TeX by changing the memory settings in /etc/texmf/texmf.cnf. In Debian and Ubuntu this can’t be done directly, but by editing /etc/texmf/texmf.d/95NonPath.cnf and running

# update-texmf

afterwards.
The memory can be increased by changing the following lines to these new values (which are the maximum values possible).

main_memory = 7999999
extra_mem_top = 7999999
extra_mem_bot = 7999999