[Tex/LaTex] How to add some latex eq or symbol in gnuplot

gnuplot

Gnuplot is power for plotting graph in scientific progress.

I have met this problem. I want to add some commands like "$\ddot{x}$".

or $\tau$ on the legend.

I see some people suggest that

plot [-5:5] [-1.5:1.5] sin(x+pi) title "$\\sin(x+\\pi)$"

But it seems it does not work.

Best Answer

To get LaTeX in labels or legends in Gnuplot, you need to use one of the terminals that produce LaTeX code.

For example, you could use the latex terminal:

set terminal latex
set out 'plot.tex'
plot [-5:5] [-1.5:1.5] sin(x+pi) title "$\\sin(x+\\pi)$"
set out

That will produce a plot.tex file that includes the plot using basic TeX statements. You can include that file in your main document using \input{plot.tex}:

\documentclass{article}
\begin{document}
\input{plot.tex}
\end{document}

Which will give you

(notice that the quality isn't overwhelming when using the latex terminal).

You can also use the epslatex terminal:

set terminal epslatex color
set out 'plot.tex'
plot [-5:5] [-1.5:1.5] sin(x+pi) title "$\\sin(x+\\pi)$"
set out

This will include a plot.tex file with all the labels, and a separate plot.eps file including the graphical elements. You can include the output using

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{plot.tex}
\end{document}


Alternatively, you could create the plots directly within LaTeX, using a package like PGFPlots or pst-plot:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    enlarge x limits=false,
    legend entries=$\sin{x+\pi}$
]
\addplot [domain=-1.5*pi:1.5*pi, smooth] {sin(deg(x+pi))};
\end{axis} 
\end{tikzpicture}
\end{document}

Related Question