5

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). 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
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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