TikZ-PGF – Tips for Skipping ‘Inf’ Values When Plotting Data with Pgfplots

pgfplotstikz-pgf

I know that with pgfplots you can skip "unbounded coords", but latex only accepts "nan", "inf" and "-inf" (and actually different capitalization for "nan" also) as the unbounded coords.

My data contains a lot of "Inf" and "-Inf" values, for which pgfplots gives an error. See the MWE:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.11}

\begin{document}
\begin{tikzpicture}
\begin{axis}[unbounded coords=jump]
\addplot coordinates {
(0,0) (10,50) (20,Inf) (30,200)
(40,inf) (50,600) (60,NaN) (80,1000)
};
\end{axis}
\end{tikzpicture}

\end{document}

Is there any way to tell latex to treat "Inf" as "inf"? I guess I could write a script to convert all my "Inf"s to "inf"s, but it would be much cleaner and easier do it through latex.

Best Answer

You can define Inf to be an alias for inf by setting declare function={Inf=inf;}:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{width=7cm,compat=1.11}

\begin{document}
\begin{tikzpicture}[declare function={Inf=inf;}]
\begin{axis}[unbounded coords=jump]
\addplot coordinates {
(0,0) (10,50) (20,Inf) (30,200)
(40,inf) (50,600) (60,NaN) (80,1000)
};
\end{axis}
\end{tikzpicture}

\end{document}