LaTeX Plot some graphs to use in LaTeX

AI Thread Summary
To successfully plot graphs in LaTeX using gnuplot, ensure to unset the output after the plot command by using "unset output" or "set output" with no arguments. This step allows the .tex file to contain the plot data properly. For the epslatex terminal, remember that curves are saved in an .eps file while labels and titles are in the .tex file, which should be included in your LaTeX document using \input{}. Additionally, using the correct formatting for titles and labels, such as \pm for plus or minus symbols, is essential. Following these guidelines will resolve issues with blank graphs and ensure proper integration with LaTeX.
Gavins
Messages
26
Reaction score
0
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.
 
Physics news on Phys.org


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?
 


\pm

\pm worked for me in the code above
 


Gavins said:
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.

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


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)

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

Similar threads

Replies
3
Views
2K
Replies
12
Views
3K
Replies
4
Views
2K
Replies
4
Views
3K
Replies
7
Views
3K
Replies
9
Views
2K
Replies
16
Views
17K
Back
Top