Plot some graphs to use in LaTeX

  • Context: LaTeX 
  • Thread starter Thread starter Gavins
  • Start date Start date
  • Tags Tags
    Graphs Latex Plot
Click For Summary

Discussion Overview

The discussion revolves around issues encountered while plotting graphs for use in LaTeX using gnuplot, specifically focusing on the epslatex terminal. Participants share their experiences with blank graphs, formatting symbols, and solutions to the problems they face.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant reports a blank graph when using the epslatex terminal, despite the axes and grid appearing correctly.
  • Another participant expresses confusion about how epslatex works and seeks help with inserting the plus or minus symbol in titles/labels.
  • Several participants confirm experiencing the same issue with blank graphs when using epslatex, indicating a shared problem.
  • A participant suggests that the output files are only partially filled with data and that changing the output file allows them to see the curve but not the labels or titles.
  • A later reply provides a solution involving unsetting the output after the plot command and including the generated .tex file in the LaTeX document.
  • The solution also clarifies the relationship between the .eps and .tex files generated by gnuplot when using the epslatex terminal.

Areas of Agreement / Disagreement

Participants generally agree on the existence of issues with blank graphs in epslatex, but there is no consensus on the underlying cause or a definitive solution until the later reply introduces a workaround.

Contextual Notes

Some participants mention being new to gnuplot, which may affect their understanding and ability to troubleshoot effectively. There is also a reference to an official updated tutorial that may provide additional context.

Who May Find This Useful

Users of gnuplot who are looking to integrate plots into LaTeX documents, particularly those encountering issues with the epslatex terminal.

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?
 


[tex]\pm[/tex]

\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 ·
Replies
3
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 16 ·
Replies
16
Views
18K
  • · Replies 7 ·
Replies
7
Views
3K