0

I'm trying to add a (very simple) 3D plot to a document using pgfplots, version 1.16. However, attempting to reproduce the very first example from the manual (page 124),

example from the pgfplots manual

actually results in this:

failed example

I'm using the exact code from the manual, i.e.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}
% this yields a 3x4 matrix:
\addplot3 [surf] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)
(0,1,0) (1,1,0.6) (2,1,0.7) (3,1,0.5)
(0,2,0) (1,2,0.7) (2,2,0.8) (3,2,0.5)
};
\end{axis}
\end{tikzpicture}
\end{document}

I'm using XeLaTeX as my compiler, but the same problem also occurs with LuaLaTeX and plain old latex.

I'm stumped, and would appreciate any help. Thank you!

1

(As usual, the answer occurred to me literally 30 seconds after asking for help.)

It turns out that the blank lines in the example -- which did not get copied when I copied and pasted the example code from the manual -- are meaningful; in other words,

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
\begin{axis}
% this yields a 3x4 matrix:
\addplot3 [surf] coordinates {
(0,0,0) (1,0,0) (2,0,0) (3,0,0)

(0,1,0) (1,1,0.6) (2,1,0.7) (3,1,0.5)

(0,2,0) (1,2,0.7) (2,2,0.8) (3,2,0.5)
};
\end{axis}
\end{tikzpicture}
\end{document}

does indeed yield the desired result. (Just why this is is another question, perhaps.)

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.