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:

\caption{Graph caption}  

and used the following package:


but I can't.

  • 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


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

Using gnuplottex:

%% compile with 'pdflatex --shell-escape myfile.tex'
\usepackage[miktex]{gnuplottex}  %% I am using miktex
    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)

Using pgfplots (code from manual):

%% compile with 'pdflatex --shell-escape myfile.tex'
\addplot gnuplot {sin(x)};

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
    Commented Sep 28, 2013 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


should have been



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:


  \caption{A caption}

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.

  • 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 .