[Tex/LaTex] Gnuplot inside LaTeX not working

gnuplotvim

I'm trying to create a gnuplot image inside my LaTeX document, but nothing is being displayed.

My gnuplot works if I do it outside LaTeX.

\begin{figure}[!ht]
\begin{gnuplot}[terminal=pdf, terminaloptions=color, scale=0.9]
set title 'Laptop Steps'
set datafile separator ','
set xlabel 'Query'
set ylabel 'Average time in ms(100 executions)'
set xrange [0:21]
set xtics 1,1,20
set logscale y
set grid ytics lt 0 lw 1 lc rgb '#bbbbbb'
set grid xtics lt 0 lw 1 lc rgb '#bbbbbb'
set key samplen 2 spacing .5 font ',8'
show grid
set style fill solid 0.8 border -1
set boxwidth 0.5 relative
plot for [i=1:14] 'benchmarks/basex-steps-laptop-transposed.csv' u (\$0+1):i title ''.i.'00    kb' with linespoints
\end{gnuplot}              
\end{figure}

I'm using vim with the latex plugin.
The structure of my project is:

main
  |-chapters/the-file-with-the-gnuplot-code
  |-benchmarks/benchmark-file.csv

For gnuplot I have this in my document:

\usepackage{gnuplottex}
\usepackage{epstopdf}

I only get the warning:

Package gnuplottex Warning: Please convert thesis-gnuplottex-fig1.gnuplot manually

Does anyone have an idea what I'm doing wrong?

Best Answer

If you run gnuplot <basename>-gnuplottex-fig1.gnuplot, you'll see gnuplot's error message

plot for [i=1:14] 'benchmarks/test.csv' u (\$0+1):i title ''.i.'00    kb' with linespoints
                                           ^
"texse-gnuplottex-fig1.gnuplot", line 16: invalid character \

gnuplot is stumbling over the \$. You don't need to escape the dollar sign in a gnuplot environment. If you remove the backslash, everything should work.

\documentclass{article}
\usepackage{gnuplottex}

\begin{document}
\begin{figure}[!ht]
\begin{gnuplot}[terminal=pdf, terminaloptions=color, scale=0.9]
set title 'Laptop Steps'
set datafile separator ','
set xlabel 'Query'
set ylabel 'Average time in ms(100 executions)'
set xrange [0:21]
set xtics 1,1,20
set logscale y
set grid ytics lt 0 lw 1 lc rgb '#bbbbbb'
set grid xtics lt 0 lw 1 lc rgb '#bbbbbb'
set key samplen 2 spacing .5 font ',8'
show grid
set style fill solid 0.8 border -1
set boxwidth 0.5 relative
plot for [i=1:14] 'benchmarks/test.csv' u ($0+1):i title ''.i.'00    kb' with linespoints
set out
\end{gnuplot}              
\end{figure}
\end{document}