Plot some graphs to use in LaTeX

1. Sep 20, 2010

Gavins

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. Sep 21, 2010

Gavins

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?

3. Sep 21, 2010

Pythagorean

Re: Gnuplot

$$\pm$$

\pm worked for me in the code above

4. Jan 14, 2011

Jackk

Re: Gnuplot

I have the same problem. Apparently I'm more than idiot since I can't solve this. What was your solution?

5. Nov 21, 2011

abrcam

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.

(I'm using gnuplot 4.4 win32 package)

Cheers

6. Jan 15, 2012

abrcam

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):
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\input{plot}
\end{figure}
\end{document}
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):
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\input{eg4}
\end{figure}
\end{document}