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

6
  • Could you try to compile with the lualatex engine?
    – pluton
    Commented Nov 18, 2015 at 15:31
  • By the way, which command line do you use for the compilation?
    – pluton
    Commented Nov 18, 2015 at 15:38
  • @pluton I had compiled with pdflatex -shell-escape (my TextMate default). Commented Nov 18, 2015 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
    Commented Nov 18, 2015 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? Commented Nov 18, 2015 at 17:53

1 Answer 1

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

You must log in to answer this question.

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