# pgfplots with gnuplot

I got a problem with latex implementing a gnuplot code. I use PdfLatex with argument "--enable-write18".

The following code should works with the first commented-out line %plot 'data.dat' u 1:2;, but it does not work with %plot 'data.dat' u 1:(f(\$2)). The proposed solution plot 'data.dat' u 1:(f(\string$2)); cannot handle the nan values in the data.dat. How can I fix this? And is there an opportunity to execute gnuplot code in TeX from an extern file? Maybe this could solve the problem and I could use $ instead of \$ or \string$? It should look like the second picture. \documentclass[11pt]{article} \usepackage{pgfplots} \usepackage{filecontents} \usepackage{verbatim} \begin{filecontents*}{data.dat} time w1 e1 w2 e2 1 3019 40 nan nan 2 3045 34 nan nan 3 3100 50 3104 24 4 3500 13 3498 90 5 3800 90 3803 12 6 NaN NaN 3980 43 7 NaN NaN 3985 80 8 3810 10 3988 34 \end{filecontents*} \begin{document} \begin{tikzpicture} \begin{axis} [ compat=newest, y tick label style={/pgf/number format/1000 sep=}, ymin=2900, ymax=4400] \addplot gnuplot [raw gnuplot,id=bal,mark=none,very thick]{ set datafile missing 'NaN'; set xrange [1:8]; set yrange [3000:4500]; f(x)=x; plot 'data.dat' u 1:(f(\string$2));
%plot 'data.dat' u 1:2;
%plot 'data.dat' u 1:(f(\$2)) }; \end{axis} \end{tikzpicture} \end{document}  - I've had better luck with asymptote's graph plotting capabilities. It is a bit harder to use (but much more flexible), while it integrates much better with LaTeX fonts and such. – vonbrand May 14 '13 at 20:37 Is it possible to convert a column (with a function of raw data) with asymptote? – Gerald May 14 '13 at 20:52 @vonbrand: PGFPlots integrates perfectly with LaTeX fonts and such, gnuplot is merely used as a number cruncher in the background here. – Jake May 14 '13 at 20:57 does anyone have an idea how to fix the first picture? – Gerald May 15 '13 at 20:59 ## 1 Answer I'm not sure what pcygni.txt file is and I got no output from that, but your main problem is \$ is a command to choose fonts and typeset a $ but (I think) you want to pass a $ to gnuplot so it is the wrong sort of quoting.

this runs without error although probably isn't the plot you want.

\documentclass[11pt]{article}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepackage{verbatim}

\begin{filecontents*}{data.dat}
time    w1  e1  w2  e2
1   3019    40  nan nan
2   3045    34  nan nan
3   3100    50  3104    24
4   3500    13  3498    90
5   3800    90  3803    12
6   nan nan 3980    43
7   nan nan 3985    80
\end{filecontents*}

\begin{document}

\begin{tikzpicture}
\begin{axis} [
y tick label style={/pgf/number format/1000 sep=},
ymin=2900,
ymax=4400]

[raw gnuplot,id=bal,mark=none,very thick]{
set xrange  [1:8];
set yrange [3000:4500];
f(x)=3600;
plot 'data.dat' u 1:(f(\string\$2));
plot 'data.dat' u 1:2
};

\end{axis}
\end{tikzpicture}

\end{document}

-
thank you for your response! –  Gerald May 14 '13 at 20:49
now the code compiles, just the "nan" values gnuplot cannot handle –  Gerald May 14 '13 at 20:49