# plot2gp – Producing gnuplot+TeX plots from Octave / Matlab

plot2gp (24.10.2013)

This page is dedicated to a program which I called plot2gp. Basically it takes an Octave or Matlab figure and produces a TeX (Tikz) plot consisting of gnuplot commands from it, like:

1 2 3 4 5 6 7 8 fig = figure(1); x = 0:0.1:2*pi; plot( x, sin(x) ); grid on; hold on; xlabel('x $\rightarrow$'); ylabel('sin(x) $\rightarrow$'); legend('sin(x)'); plot2gp( 'test.tex', fig );

The output “test.tex” can then be used in LaTeX like this:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 \documentclass[10pt]{article} \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage[english]{babel} \usepackage{blindtext}   \usepackage[utf8x]{inputenc} \usepackage{gnuplottex} \usepackage{gnuplot-lua-tikz}   \begin{document}   \begin{figure}[h] \centering \input{test.tex} \caption{This is a test plot in Octave/Matlab.} \end{figure}   \end{document}

The result looks like this:

plot_test

Why didn’t i use matlab2tikz and pgfplots ?:

For sure, i did use both in order to produce (really) good looking graphs for scientific publications! And I still strongly recommend these two programs in combination with LaTeX etc. But I had a little problem, which I couldn’t solve with pgfplots: Until now, pgfplots is missing a decent zBuffer algorithm, which I needed for a few pictures. Basically, I needed to plot two (or more) surf plots in one plot. There exists certain solutions in the net, but they all involve to much user interacton (doing the zBuffering by hant etc.). So I decided to do these plots with gnuplot. And luckily, there is a way to include gnuplot plots easily into LaTeX.

Update 24.10.2013:

• Some minor big fixes.

Initial version: