# Interactive surface plot with pgfplots

I know that it is possible to embed three-dimensional files into PDFs with \LaTeX which can then actively be interacted with by the reader (see here for example).

I have a surface plot I made with pgfplots. Is there any way to have this surface plot interactive, i.e. to make it like so that the reader can rotate the surface as he/she wishes?

This will obviously only work with a limited set of readers (probably only recent versions of Adobe Reader), but for the sake of trying I'm willing to work with the consequences of this.

Pgfplots supports two-dimensional projections only.

• I probably couldn't get a more precise answer :) – Habi Oct 10 '13 at 7:35
• Well, two years ago I thought about implementing support for interactive 3d graphics in pgfplots because it appears to be interesting. But it is also very involved... – Christian Feuersänger Oct 10 '13 at 20:58
• Here is a further remark for others who might have stumbled over this answer: pgfplots supports interactive results - just for different use-cases: you can click on data points and the reader displays customizable meta data. Refer to the clickable lib of pgfplots for details. – Christian Feuersänger Nov 10 '13 at 13:17

I'm not sure whether you can do this with pgfplots, but Asymptote excels at this sort of thing.

For example, here is a MWE, in the form of a Beamer slide, that includes an interactive figure I created for a lecture on multiple regression. If you open this is Acrobat Reader you can click on the plot and then rotate, zoom, etc.

Since I like to keep my LaTeX and figure code separate I split this into two files, asyslide.tex and multiregr.asy.

### asyslide.tex

\documentclass{beamer}
\usepackage[inline]{asymptote}

\begin{document}
\begin{frame}
\frametitle{Geometry of Multiple Regression}
\begin{center}
\asyinclude[height=2.5in,inline=true]{multiregr.asy}
\end{center}
\end{frame}
\end{document}


### multiregr.asy

settings.render=10;
settings.prc=true;
settings.outformat="pdf";

import three;
size(200);
defaultpen(fontsize(9));
currentprojection=perspective(4,2,1.5);

/* draw the X,Y-plane */
path3 xplane = (0,0,0)--(2,0,0)--(2,2,0)--(0,2,0)--cycle;
draw(xplane,gray);

/* X vectors */
path3 x1 = (0,0,0)--(1.75,1,0);
draw(Label("$\mathbf{x}_1$", 1),x1,Arrow3);

path3 x2 = (0,0,0)--(0.5,1.9,0);
draw(Label("$\mathbf{x}_2$", 1, align=S),x2,Arrow3);

path3 y= (0,0,0)--(1.8, 1.5,1.2);
draw(Label("$\mathbf{y}$", 0.75, align=2*W),y,Arrow3);

/* Project Y into subspace of Xs */
path3 projy = planeproject(xplane)*y;
triple endpoint = invert(point(length(projy)));

draw(Label("$\mathbf{\widehat{y}}$", 1, align=E),projy,red,Arrow3);
draw(Label("$\mathbf{e}$", 0.75,align=RightSide),(1.8,1.5,0)--(1.8,1.5,1.2),red+dashed,Arrow3);


You can compile this example as:

pdflatex asyslide.tex
asy asyslide*.asy
pdflatex asyslide.tex


This generates the following output:

• At work (Scientific Linux 6, Texlive 2012), I cannot complete the asy asyslide*.asy step. I get informed that the runtime does not support onscreen rendering, that I should install the glut library (I have freeglut), run ./configure, and recompile. Including switching from pgfplots to Asymptote that seems like a big step unfortunately. – Habi Oct 10 '13 at 7:40
• @Habi: Unfortunately I can't help you with Asymptote issues you're running into on Scientific Linux, as I primarily use the build of Asymptote that is distributed with MacTeX and it's always just worked "out of the box." Asymptote is very powerful, so if you anticipate doing lots of technical illustrations it's probably worth the effort to get it working. But if this is just a "one off" need than you may want to consider keeping things simple and using the non-interactive pgfplot you've already created. – Paul M. Oct 10 '13 at 12:55
• At the moment I only wanted to have plots interactive, switching my workflow from pgf/TikZ to Asymptote seems overkill for that. Even though your answer is great, I still accepted the (negative) answer from the author of pgfplots below. – Habi Oct 18 '13 at 9:39