# How can we import the gnuplot output in LaTeX?

I am using the gnuplot and create the myploy.tex as following:

set terminal epslatex
set output 'mplot.tex'
set xlabel "Avg. No. of demand duration (slot) "
set ylabel "Acceptence rate (%)"
set grid xtics ytics
set key right bottom

set style line 1 lw 1 lc 3 pt 7
set style line 2 lw 1 lc 1 pt 5
set style line 3 lw 1 lc 0 pt 9
set style line 4 lw 1 lc 4 pt 3

plot "AcceptanceRate_Ser.txt" using 2:4:5:6 title "NoMig" with errorlines linestyle 1,\
"AcceptanceRate_Ser.txt" using 2:7:8:9 title "FlowMig" with errorlines linestyle 2 ,\
"AcceptanceRate_Ser.txt" using 2:10:11:12 title "VMMig" with errorlines linestyle 3, \
"AcceptanceRate_Ser.txt" using 2:13:14:15 title "NoRis" with errorlines linestyle 4


Finally, I have myplot.tex and myplot.eps.

I need to import them in the LaTeX file as figure I did the following:

\begin{figure}[!]
\begin{center}
\input{myplot.tex}
\caption{Graph caption}
\label{graph:graph1}
\end{center}
\end{figure}


and used the following package:

\usepackage{graphicx}
\usepackage{txfonts}
\usepackage{epstopdf}


but I can't.

• You can use gnuplottex and use gnuplot code directly in your tex file. Also, pgfplots integrates gnuplot seemlessly. – user11232 Sep 27 '13 at 5:07
• "but I can't". Can you give more details. Are you using the "-shell-escape" option? (to run epstopdf). – alfC Sep 27 '13 at 6:53

Here are the methods that allow us to use gnuplot directly inside the .tex file.

Using gnuplottex:

%% compile with 'pdflatex --shell-escape myfile.tex'
\documentclass{standalone}
\usepackage[miktex]{gnuplottex}  %% I am using miktex
\begin{document}
\begin{gnuplot}[terminal=pdf,terminaloptions=color]
unset key
set samples 10000
set format '%g'
set xlabel "Avg. No. of demand duration (slot) "
set ylabel "Acceptence rate (%)"
set xrange [-6:6]
set yrange [0:0.41]
f(n,x) = gamma(.5*(n+1))/(sqrt(n*pi)*gamma(.5*n))*((1+x**2/n)**(-.5*(n+1)))
plot for[i=1:20] f(i,x)
\end{gnuplot}
%
\end{document}


Using pgfplots (code from manual):

%% compile with 'pdflatex --shell-escape myfile.tex'
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\end{axis}
\end{tikzpicture}
\end{document}


Both need to be compiled with --shell-escape option and you can use pdflatex directly.

• These are two further methods, not the methods, and the one used in the question is also valid to include gnuplot output. – Christoph Sep 28 '13 at 11:06

Since you have not included the output and errors produced, it is hard to determine exactly what is wrong.

However, your problem could be that you don't have \usepackage{colors} in your preamble.

EDIT: Looking at it again it could also be that you added .tex when using the \input-command. I believe

\input{myplot.tex}


should have been

\input{myplot}


END OF EDIT.

To try something a little simpler than the sought solution, you can try to have gnuplot output a tex-document that will compile by it self. The following code does that.

set terminal epslatex size 9cm,7cm standalone
set output 'test.tex'

unset key
plot x**2;


Then running latex test.tex and dvipdf test.dvi, you get a pdf looking like this:

Looking at the produced test.tex file you will see that it is including the LaTeX pakcages graphicx, color and geometry. I would start making sure I have those included in my main document as well.

To see if I can the gnuplot-generated graph I make a new tex-file comp_test.tex with the content:

\documentclass{article}
\usepackage{geometry}
\usepackage{color}
\usepackage{graphicx}

\begin{document}
\begin{figure}
\begin{center}
\include{test}
\end{center}
\caption{A caption}
\end{figure}
\end{document}


and I make sure to remove the part of the gnuplot-file that says standalone:

set terminal epslatex
set output 'test.tex'

unset key
plot x**2;


Now running gnuplot test.gnu, latex comp_test.tex, dvipdf comp_test.dvi I get a pdf that looks like this: