Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

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

share|improve this answer
3  
Another day, another pgfplots option :) –  Ryan Reich Jan 19 '12 at 21:26
add comment

In the middle of the loop \i=0, so that there will be a division by zero. Mathematics generally does not like that (though interestingly the code compiles on my computer). So you have to split the loop into two loops, excluding zero:

\documentclass[12pt]{article}

\usepackage{pgfplots}

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

\end{document}

result

share|improve this answer
2  
Once division by zero is allowed, 1 becomes zero, then all hell breaks loose. :-) –  Matthew Leingang Mar 18 '11 at 18:34
    
@Matthew: Now, what does that say about my computer? –  Caramdir Mar 18 '11 at 18:42
    
Haha! Thanks, works fine! –  0sh Mar 18 '11 at 20:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.