Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Plot some graphs to use in LaTeX

  1. Sep 20, 2010 #1
    Hey guys, I am trying to plot some graphs to use in LaTeX. In gnuplot, I run the command

    set term epslatex
    set output "graph.tex"
    plot ......

    However, my graph is blank. The axis and grid are there but text and curves are missing. If I set the terminal to aquaterm or X11, they look perfet. I've tried playing around with different options but I still haven't figured anything out yet. I've only just started using gnuplot so I'm still getting used to it.
  2. jcsd
  3. Sep 21, 2010 #2
    Re: Gnuplot

    Ah, I'm an idiot. I don't know how epslatex works but I've figured it now.

    One quick question, how do you put in the plus or minus symbol into titles/labels?
  4. Sep 21, 2010 #3


    User Avatar
    Gold Member

    Re: Gnuplot


    \pm worked for me in the code above
  5. Jan 14, 2011 #4
    Re: Gnuplot

    I have the same problem. Apparently I'm more than idiot since I can't solve this. What was your solution?
  6. Nov 21, 2011 #5
    Re: Gnuplot

    Adding another idiot to the list (no offense Jackk) ... I'm having the same problem.

    What's strange is that after issuing the "plot" command, the tex and eps files are only partially filled with data but still kept open for writing by gnuplot (you can't delete the .tex file).

    Also, if after issuing the "plot" command, I change the output to a different file, then the initial file is then written to and closed and I can see the curve in the eps file, but none of the other bits (labels, title, etc).

    I'm stumped and I couldn't find a solution on the net ... which kind of means I'm missing something easy.

    Anyone, please?

    (I'm using gnuplot 4.4 win32 package)

  7. Jan 15, 2012 #6
    Re: Gnuplot

    I also fixed it quickly after posting and felt like an idiot. However, I'm posting the solution here (still surprised nobody bothered to until now).

    First, there is an official updated tutorial that i recommend you read regarding gnuplot with latex/epslatex here (includes info about v4.4): http://www.gnuplot.info/docs/tutorial.pdf.

    Basically, you need to unset the output after issuing the "plot" command by doing either "unset output" or "set output" (no arguments) and then to call \input{} on the .tex file output by gnuplot. For latex terminal:

    Code (Text):
    set terminal latex
    set output "plot.tex"
    plot x**2
    unset output
    now plot.tex will contain the actual plot and in your latex document you need to do:

    Code (Text):
    If you use the epslatex terminal (I find it much better than the latex one which yields blocky curves) then you need to know that the curves are output in an .eps file and the other info (labels etc) in an .tex file. The .tex file contains all code that also includes the .eps file so you only include this in the same way as above, e.g.:

    Code (Text):
    set terminal epslatex
    set output "eg4.tex"
    set format y "$%g$"
    set format x "$%.2f$"
    set title 'This is $\sin(x)$'
    set xlabel "This is the $x$ axis"
    set ylabel "$\\sin(x)$"
    unset key
    set xtics -pi, pi/4
    plot [-pi:pi] [-1:1] sin(x)
    unset output
    This will ouptut eg4.eps and eg4.tex and you'll notice that the eg4.eps file only contains the curve and if you edit eg4.tex you will see it calls \includegraphics{eg4} which includes eg4.eps. Now from your latex document just do the same:

    Code (Text):
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook