Hi,
how can I plot an error function using Tikz?
Thanks
Graphics, Figures & Tables ⇒ Error function
Error function
Last edited by jhapk on Wed Jul 07, 2010 3:52 am, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

Error function
For functions like erf(x) which are not one of the built-in math functions in TikZ, I use the Gnuplot TikZ terminal, which lets you export any type of plot that Gnuplot can draw into TikZ format. Read the installation instructions; on the Gnuplot end you'll need version 4.40, and on the LaTeX end you'll need to install the gnuplot-lua-tikz.sty file. After you've set it all up, you can do something like this in Gnuplot:
That will create a tikzpicture environment in a file called erf.tex, which you can then include in your LaTeX document. Here's a complete example:
You can tweak the erf.tex file to suit your needs. I always change the numbers on the axes to math mode.
Code: Select all
set terminal lua tikz originreset size 5in,3in
set xlabel '$x$'
set ylabel '$y$'
set output 'erf.tex'
plot [0:pi] erf(x)
Code: Select all
\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{gnuplot-lua-tikz}
\begin{document}
Here is a graph of the error function:
\begin{center}
\input{erf}
\end{center}
\end{document}
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Error function
The method introduced by shadgrind seems to me a little bit too complicated. The pgfplots package offers a very easy interface to Gnuplot.
For more information refer to the package manual. Note the special remarks about the prerequisites for making Gnuplot work with this package (keyword: option -shell-escape for the compiler).
Best regards and welcome to the board
Thorsten
Code: Select all
\documentclass{minimal}
\usepackage{amsmath}
\usepackage{pgfplots}
\DeclareMathOperator{\erf}{erf}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
xlabel=$x$,
ylabel=$\erf(x)$
]
\addplot[smooth] gnuplot[id=erf]{erf(x)};
\end{axis}
\end{tikzpicture}
\end{document}
Best regards and welcome to the board
Thorsten
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Error function
Thanks Thorsten,
that worked smoothly.
that worked smoothly.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: Error function
Now that the problem is solved, please act like you have already been directed in my last reply.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10