10

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?

0

1 Answer 1

12

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

1
  • Excellent! Your solution worked perfectly. Thank you for your help.
    – Dillmo
    Commented Mar 27, 2014 at 0:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .