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've been using pgfplots for graphing for a while, now, and have recently run into a situation where I need to graph rational functions. Most of these have worked out fine, but one has caused me to get a "Dimension too large" error. Here is my code:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

  \begin{tikzpicture}
    \begin{axis}[axis lines=middle, ymax=10, ymin=-10, xlabel=$x$, ylabel=$y$]
      \addplot[only marks, scatter, scatter src=explicit, point meta=y] coordinates {
        (-4, 4)
        (-3, 5)
        (-2, 10)
        (-1, -5)
        (0, 0)
        (1, 1)
        (2, 1.429)
      };
      \addplot[smooth, domain=-10:-1.5, variable=\x, samples=301, unbounded coords=jump, variable=\x] {(5 * \x) / (2 * \x + 3)};
      \addplot[smooth, domain=-1.5:10, variable=\x, samples=301, unbounded coords=jump, variable=\x] {(5 * \x) / (2 * \x + 3)};
      \addplot[dashed, domain=-10:10] {5 / 2};
      \draw[dashed] ({axis cs:-1.5,0}|-{rel axis cs:0,0}) -- ({axis cs:-1.5,0}|-{rel axis cs:0,1});
    \end{axis}
  \end{tikzpicture}

\end{document}

This can be avoided by making the domains of the second and third plots restricted to -3:-1.5 and 1.5:3, respectively. I don't see how I would get too big a number, and can only imagine this being a decimal underflow issue. How can I fix this problem?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

unbounded coords key works only you get a precise inf as a coordinate. However if the coordinate gets too big but not inf it tries to process that number and you get this error. In order to avoid such problems use restrict <x,y> to domain key

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[axis lines=middle, ymax=10, ymin=-10, xlabel=$x$, ylabel=$y$,restrict y to domain=-10:10 ]
      \addplot[only marks, scatter, scatter src=explicit, point meta=y] coordinates {
        (-4, 4)
        (-3, 5)
        (-2, 10)
        (-1, -5)
        (0, 0)
        (1, 1)
        (2, 1.429)
      };
      \addplot[domain=-10:-1.5,samples=301, unbounded coords=discard] {((5*x)/(2*x + 3))};
      \addplot[domain=-1.5:10, samples=301, unbounded coords=discard] {((5*x)/(2*x + 3))};
      \addplot[dashed, domain=-10:10] {5 / 2};
      \draw[dashed] ({axis cs:-1.5,0}|-{rel axis cs:0,0}) -- ({axis cs:-1.5,0}|-{rel axis cs:0,1});
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Excellent! Your solution worked perfectly. Thank you for your help. –  Dillmo Mar 27 at 0:49

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.