[Tex/LaTex] Best way to generate nice function plots in LaTeX

big-listdiagrams

Which is the best way to put function plots into a LaTeX document?

Best Answer

To extend the answer from Mica, pgfplots can do calculations in TeX:

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[ 
    xlabel=$x$,
    ylabel={$f(x) = x^2 - x +4$}
  ] 
    \addplot {x^2 - x +4}; 
  \end{axis}
\end{tikzpicture}
\end{document}

pgfplots drawing of f(x) = x^2 - x +4

or using GNUplot (requires --shell-escape):

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[
    xlabel=$x$,
    ylabel=$\sin(x)$
  ]
    \addplot gnuplot[id=sin]{sin(x)}; 
  \end{axis}
\end{tikzpicture}
\end{document}

pgfplots and gnuplot drawing of sin(x)

You can also pre-calculate values using another program, for example a spreadsheet, and import the data. This is all detailed in the manual.

Related Question