Using TikZ spy in 3D

Very similar to Jasper Habicht's nice answer except that you do not have to adjust the lens transformation by hand. So this works regardless of which vectors you choose for you 3D coordinate system.

\documentclass[tikz,margin=0.5cm]{standalone}
\usetikzlibrary{3d,spy}

\begin{document}

\begin{tikzpicture}[y={(1cm,-0.5cm)},x={(1cm,0.5cm)}, z={(0cm,1cm)},spy using outlines={rectangle, magnification=4, size=2cm, connect spies}]

\coordinate (O) at (1, -1 -0.5);
\draw[->] (O) -- +(0.5, 0,  0) node [right] {$x$};
\draw[->] (O) -- +(0,  0.5, 0) node [below] {$y$};
\draw[->] (O) -- +(0,  0, 0.5) node [above] {$z$};

\draw [fill=blue!20] (0,0,0) -- (3,0,0) -- (3,2,0) -- (0,2,0) -- cycle;

\begin{scope}[canvas is yx plane at z=0,transform shape,every node/.style={scale=0.2}]
\node [align=center] (Text) at (1,1.5) {Make me\\ big!};
\pgfgettransform{\mytrafo} % read off transformation
\xdef\mytrafo{\mytrafo} % globalize macro
\end{scope}

\spy[lens={/utils/exec={\pgfsettransform{\mytrafo} % reinstall and invert trafo
\pgftransforminvert},scale=3}] on (Text) in node at (1,1,3);

\end{tikzpicture}
\end{document}

enter image description here


There is the lens option that allows you to apply transformations on the small “spy” picture (see para 68.3 in the TikZ/PGF manual [v 3.0.1a]):

\documentclass[tikz,margin=0.5cm]{standalone}
\usetikzlibrary{3d,spy}

\begin{document}

\begin{tikzpicture}[y={(1cm,-0.5cm)},x={(1cm,0.5cm)}, z={(0cm,1cm)},spy using outlines={rectangle, magnification=4, size=2cm, connect spies}]

\coordinate (O) at (1, -1 -0.5);
\draw[->] (O) -- +(0.5, 0,  0) node [right] {$x$};
\draw[->] (O) -- +(0,  0.5, 0) node [below] {$y$};
\draw[->] (O) -- +(0,  0, 0.5) node [above] {$z$};

\draw [fill=blue!20] (0,0,0) -- (3,0,0) -- (3,2,0) -- (0,2,0) -- cycle;

\begin{scope}[canvas is yx plane at z=0,transform shape,every node/.style={scale=0.2}]
\node [align=center] (Text) at (1,1.5) {Make me\\ big!};
\end{scope}

\spy[lens={xslant=-1,yslant=.5,scale=3}] on (Text) in node at (1,1,3);

\end{tikzpicture}
\end{document}

enter image description here

Tags:

3D

Spy

Tikz Pgf