8

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.

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

2 Answers 2

9

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}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot gnuplot {sin(x)};
\end{axis}
\end{tikzpicture}
\end{document}

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

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

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: x**2

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: x**2 graph included in latex

If you would like to read more about gnuplot I would strongly recommend visiting http://gnuplotting.org. I learned about the LaTeX-terminal specifically from this article http://www.gnuplotting.org/tag/epslatex/.

Good luck.

3
  • I copied your solution. 1: Created a new gnuplot script and include the 4 lines of gnuplot code you gave. I ran this with gnuplot. 2: I copied and pasted the latex commands into a new texstudio document and compiled it. I got a load of errors, the first of which is "missing } inserted". Any ideas what is wrong? Commented Mar 29, 2017 at 14:01
  • I am finding this very frustrating as nothing I seem to try is working, and i have tried many different latex like terminals etc, so any help would be appreciated. Commented Mar 29, 2017 at 14:02
  • Okay I've sorted it - the problem is I was being a moron. Commented Mar 29, 2017 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .