[Tex/LaTex] Dimension too large while plotting with pgfplots

dimensionserrorspgfplots

I have the following pgfplots code:

\begin{tikzpicture}
\begin{axis}[domain=-8:2]
\foreach \i in {-10,-9.8,...,10} {\addplot+[smooth] {-x/\i+\i};}%
\end{axis}
\end{tikzpicture}

I need several line-plots in order for the parabolic pattern to emerge, hence the for loop with a 0.2 increment. Unfortunately, this gives me the dimension too large error. What can I do?

Best Answer

Besides the obvious 1/0 division, the question is not about math but about TeX, i.e. why pgfplots fails. pgfplots probably complains because whatever internal represenation of 1/0 is "too large" to be plotted. The solution is to use restrict y to domain

\documentclass[12pt]{article}

\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
\begin{axis}[domain=-8:2, restrict y to domain=-10:10]
\foreach \i in {-10,-9.8,...,10} {\addplot+[no markers, solid, smooth] {-x/\i+\i};}%
\end{axis}
\end{tikzpicture}

\end{document}

(Having said that, it is anyway dangerous to allow a division by zero in general.)

emerging parabola

Related Question