6

I'm trying to make a contour plot with pgfplots and gnuplot, but I get the error "dimension too large". Why? That seems like a TeX error, I thought gnuplot was doing the calculations?

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=0.8\textwidth,
        view={0}{90},
        grid=major,
        xlabel = $x$,
        ylabel = $y$,
        xmin=-2,
        ymin=-2,
        xmax=+2,
        ymax=+2,
        unit vector ratio = 1,
        ]
    \addplot3[
        contour gnuplot={
            number=10,
            contour label style={
                nodes={text=black}
                }
            },
        contour/draw color={black},
        contour/label distance=1000pt,
        thick,
        samples=50]
        { 3*x^2 + 4*y^3 + 2*x^3 - 12*y };
    \end{axis}
\end{tikzpicture}
\end{document} 

If I add restrict z to domain=-20:30 (which should encompass all relevant output values of f(x,y)=3*x^2 + 4*y^3 + 2*x^3 - 12*y in the given domain), an output is produced but with only one contour (not 10 contours as desired).

I'm expecting something similar to:

enter image description here

  • Could you try to compile with the lualatex engine? – pluton Nov 18 '15 at 15:31
  • By the way, which command line do you use for the compilation? – pluton Nov 18 '15 at 15:38
  • @pluton I had compiled with pdflatex -shell-escape (my TextMate default). – Chris Chudzicki Nov 18 '15 at 16:04
  • gnuplot does the calculation, some point (hidden) in the output is still too large for tikz. use the keyword ` restrict y to domain' (look in the manual). http://tex.stackexchange.com/a/13838/1871 – alfC Nov 18 '15 at 17:32
  • @alfC See comment in question about restrict z to domain=-20:30 (which I suspect is the relevant command in this case, since we're using addplot3. Do you know why restricting z domain might be limiting the number of contours? – Chris Chudzicki Nov 18 '15 at 17:53
  • Good question, one may think that even if this is the a sort of 3d plot, the direction z should be projected out. I don't know. – alfC Nov 18 '15 at 18:04

1 Answers1

5

I guess that even though I specified xmin=-2, xmax=+2, ymin=-2, ymax=+2, pgfplots was still sampling outside this range. If I specify the domains explicitly using domain=-2:2 and y domain=-2:2, compilation works.

Still, I really thought gnuplot was doing the calculation? So why was dimensions too large?

\documentclass{standalone}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        width=0.8\textwidth,
        view={0}{90},
        grid=major,
        xlabel = $x$,
        ylabel = $y$,
        xmin=-2,
        ymin=-2,
        xmax=+2,
        ymax=+2,
        unit vector ratio = 1,
        ]
    \addplot3[
        contour gnuplot={
            number=10,
            contour label style={
                nodes={text=black}
                }
            },
        contour/draw color={black},
        contour/label distance=1000pt,
        thick,
        domain = -2:2,
        y domain = -2:2,
        samples=50]
        { 3*x^2 + 4*y^3 + 2*x^3 - 12*y };
    \end{axis}
\end{tikzpicture}
\end{document} 

enter image description here