Plot some graphs to use in LaTeX

In summary, the conversation discusses the issue of a blank graph when using the epslatex terminal in gnuplot. The solution is to unset the output after issuing the "plot" command and then call \input{} on the .tex file output by gnuplot. For the epslatex terminal, the curves are output in an .eps file and the other information in a .tex file, which can be included in a latex document using \input{}.
  • #1
Gavins
27
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
  • #2


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


[tex]\pm[/tex]

\pm worked for me in the code above
 
  • #4


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?
 
  • #5


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
 
  • #6
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}
 

1. How do I plot graphs in LaTeX?

In LaTeX, you can use the "tikzpicture" environment to plot graphs. This environment allows you to specify coordinates and draw lines and curves using specific commands. You can also use the "pgfplots" package to create more complex graphs and plots.

2. Can I import data from external sources to plot in LaTeX?

Yes, you can import data from external sources such as CSV files or Excel spreadsheets to plot in LaTeX. The "pgfplots" package has a built-in function for importing data, or you can use the "datatool" package to import and manipulate data in LaTeX.

3. How do I customize the appearance of my graphs in LaTeX?

You can customize the appearance of your graphs by using various options and settings in the "tikzpicture" or "pgfplots" environments. These options allow you to change the color, style, and labels of your graphs to suit your needs.

4. Is it possible to add multiple graphs in one LaTeX document?

Yes, you can add multiple graphs in one LaTeX document by using the "subfigure" or "subcaption" packages. These packages allow you to create subfigures within a single figure, making it easier to include multiple graphs in one document.

5. How can I include my graphs in a LaTeX document?

You can include your graphs in a LaTeX document by using the "includegraphics" command and specifying the file path of your graph. You can also use the "figure" environment to add captions and labels to your graphs, making them easier to reference in your document.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
801
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
16
Views
17K
Back
Top