1

I am looking to create a diagram that has a single spot (which is a small part of the larger picture) that is magnified such that in the magnified view, the spot is replaced with something that has a lot more detail.

In the example image, I would like to only see the red dot in the unmagnified view (similar to the singular red dot to the left), and then only see the hexagons and arrows in the magnified view (with no red dot).

enter image description here

My example so far uses the spy TikZ package to magnify, but I am not aware of being able to change the details in the region of magnification. Here is my code:

\documentclass[crop,tikz]{standalone}


\usepackage{tikz}

\usepackage{fourier}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,3d,math, decorations,spy}


\begin{document}

\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}[tdplot_main_coords,font=\sffamily, spy using outlines={rectangle,color=purple,magnification=2,size=4cm,connect spies}]

    %Set up plane and lattice points
    \coordinate (Shift) at (2,2,0.5);
    \tdplotsetrotatedcoordsorigin{(Shift)}
    \begin{scope}[tdplot_rotated_coords]
        % plane
        \draw[fill=blue,opacity=0.2] (0,-2,4) -- (0,2,4) -- (0,2,0) -- (0,-2,0) -- cycle;
        \coordinate (Q) at (0,1,1.414);
        \coordinate (P) at (0,-1,1.414);
        % Red lattice points
        \draw[fill=red] (Q) circle (4pt);
        \draw[fill=red] (P) circle (4pt);
    \end{scope}


    \tdplotsetrotatedcoords{90}{90}{135}
    \tdplotsetrotatedcoordsorigin{ (Q) }
    \begin{scope}[tdplot_rotated_coords]

        \def\x{0.3}

        \coordinate (h11) at (\x, -\x, 0);
        \coordinate (h12) at (-\x, \x, 0);
        \coordinate (h21) at (\x, 0, -\x);
        \coordinate (h22) at (-\x, 0, \x);
        \coordinate (h31) at (0, \x, -\x);
        \coordinate (h32) at (0, -\x, \x);

        \coordinate (h'11) at (\x, \x, -2*\x);
        \coordinate (h'12) at (-\x, -\x, 2*\x);
        \coordinate (h'31) at (2*\x, -\x, -\x);
        \coordinate (h'32) at (-2*\x, \x, \x);
        \coordinate (h'21) at (\x, -2*\x, \x);
        \coordinate (h'22) at (-\x, 2*\x, -\x);


        % red hexagon half1
        \fill[fill=red!50!blue,opacity=0.5] (h11) -- (h21) --  (\x/2,\x/2,-\x) -- (-\x/2, -\x/2, \x) -- (h32) -- cycle; 
        % red hexagon half2
        \fill[fill=red,opacity=0.5] (h12) -- (h31) --  (\x/2,\x/2,-\x) -- (-\x/2, -\x/2, \x) --  (h22) -- cycle; 
        % green hexagon half1
        \fill[fill=green!50!blue,opacity=0.5] (h'11) -- (h'31) -- (h'21) -- (h'12) -- cycle;
        % green hexagon half2
        \fill[fill=green!70!gray,opacity=0.5](h'11) -- (h'22) -- (h'32) -- (h'12) -- cycle; 
        % black arrows
        \draw[ color=black] (h12) -- (Q); \draw[densely dotted,->, -stealth] (Q) -- (h11) node[right=-2pt] {\tiny $\tau_1$};
        \draw (Q) -- (h22); \draw[densely dotted, ->,-stealth, color=black] (Q) -- (h21) node[above=-1pt] {\tiny $\tau_2$};
        \draw[ color=black] (h31) -- (Q); \draw[densely dotted,->,-stealth] (Q) -- (h32) node[right=-2pt ] {\tiny $\tau_3$};
        % white arrows
        \draw[->, -stealth,dashed, color=white] (h'12) -- (h'11) node[left=-1pt] {\tiny $\tau'_1$};
        \draw[ dotted, color=white] (h'21) --  (Q); \draw[->, -stealth,color=white] (Q) -- (h'22) node[left=-1pt] {\tiny $\tau'_2$};
        \draw[ dotted, color=white] (h'31) -- (Q); \draw[->,-stealth,color=white] (Q) -- (h'32) node[below right=-3pt] {\tiny $\tau'_3$};

\end{scope}

\spy on (Q) in node at (2,8,4); %


\end{tikzpicture}

\end{document}
1

Welcome! You can add these circles outside of the spy scope. Since you probably do not want to set up the transformations again, it may make sense to save the paths in the scope where you currently draw them, i.e. instead of

\draw[fill=red] (Q) circle (4pt);
\draw[fill=red] (P) circle (4pt);

we use

\path[save path=\circleQ] (Q) circle[radius=4pt];
\path[save path=\circleP] (P) circle[radius=4pt];

and really draw them outside of the spy scope with

\draw[fill=red,reuse path=\circleP];
\draw[fill=red,reuse path=\circleQ];

Here is a full example:

\documentclass[crop,tikz]{standalone}

\usepackage{fourier}
\usepackage{tikz-3dplot}
\usetikzlibrary{spy}

\makeatletter
\tikzset{% https://tex.stackexchange.com/a/26664/194703
    reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother


\begin{document}

\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}[tdplot_main_coords,font=\sffamily]
\begin{scope}[ spy using outlines={rectangle,color=purple,magnification=2,size=4cm,connect spies}]
    %Set up plane and lattice points
    \coordinate (Shift) at (2,2,0.5);
    \tdplotsetrotatedcoordsorigin{(Shift)}
    \begin{scope}[tdplot_rotated_coords]
        % plane
        \draw[fill=blue,opacity=0.2] (0,-2,4) -- (0,2,4) -- (0,2,0) -- (0,-2,0) -- cycle;
        \coordinate (Q) at (0,1,1.414);
        \coordinate (P) at (0,-1,1.414);
        % Red lattice points
        \path[save path=\circleQ] (Q) circle[radius=4pt];
        \path[save path=\circleP] (P) circle[radius=4pt];
    \end{scope}

    \tdplotsetrotatedcoords{90}{90}{135}
    \tdplotsetrotatedcoordsorigin{ (Q) }
    \begin{scope}[tdplot_rotated_coords]

        \def\x{0.3}

        \coordinate (h11) at (\x, -\x, 0);
        \coordinate (h12) at (-\x, \x, 0);
        \coordinate (h21) at (\x, 0, -\x);
        \coordinate (h22) at (-\x, 0, \x);
        \coordinate (h31) at (0, \x, -\x);
        \coordinate (h32) at (0, -\x, \x);

        \coordinate (h'11) at (\x, \x, -2*\x);
        \coordinate (h'12) at (-\x, -\x, 2*\x);
        \coordinate (h'31) at (2*\x, -\x, -\x);
        \coordinate (h'32) at (-2*\x, \x, \x);
        \coordinate (h'21) at (\x, -2*\x, \x);
        \coordinate (h'22) at (-\x, 2*\x, -\x);


        % red hexagon half1
        \fill[fill=red!50!blue,opacity=0.5] (h11) -- (h21) --  (\x/2,\x/2,-\x) -- (-\x/2, -\x/2, \x) -- (h32) -- cycle; 
        % red hexagon half2
        \fill[fill=red,opacity=0.5] (h12) -- (h31) --  (\x/2,\x/2,-\x) -- (-\x/2, -\x/2, \x) --  (h22) -- cycle; 
        % green hexagon half1
        \fill[fill=green!50!blue,opacity=0.5] (h'11) -- (h'31) -- (h'21) -- (h'12) -- cycle;
        % green hexagon half2
        \fill[fill=green!70!gray,opacity=0.5](h'11) -- (h'22) -- (h'32) -- (h'12) -- cycle; 
        % black arrows
        \draw[ color=black] (h12) -- (Q); \draw[densely dotted,->, -stealth] (Q) -- (h11) node[right=-2pt] {\tiny $\tau_1$};
        \draw (Q) -- (h22); \draw[densely dotted, ->,-stealth, color=black] (Q) -- (h21) node[above=-1pt] {\tiny $\tau_2$};
        \draw[ color=black] (h31) -- (Q); \draw[densely dotted,->,-stealth] (Q) -- (h32) node[right=-2pt ] {\tiny $\tau_3$};
        % white arrows
        \draw[->, -stealth,dashed, color=white] (h'12) -- (h'11) node[left=-1pt] {\tiny $\tau'_1$};
        \draw[ dotted, color=white] (h'21) --  (Q); \draw[->, -stealth,color=white] (Q) -- (h'22) node[left=-1pt] {\tiny $\tau'_2$};
        \draw[ dotted, color=white] (h'31) -- (Q); \draw[->,-stealth,color=white] (Q) -- (h'32) node[below right=-3pt] {\tiny $\tau'_3$};

\end{scope}

\spy on (Q) in node at (2,8,4); %
\end{scope}
\draw[fill=red,reuse path=\circleP];
\draw[fill=red,reuse path=\circleQ];
\end{tikzpicture}

\end{document}

enter image description here

Notice, though, that this changes the ordering of the paths. If you want the same ordering as in your document, you can use the backgrounds library.

\documentclass[crop,tikz]{standalone}

\usepackage{fourier}
\usepackage{tikz-3dplot}
\usetikzlibrary{backgrounds,spy}

\makeatletter
\tikzset{% https://tex.stackexchange.com/a/26664/194703
    reuse path/.code={\pgfsyssoftpath@setcurrentpath{#1}}
}
\makeatother


\begin{document}

\tdplotsetmaincoords{60}{120}
\begin{tikzpicture}[tdplot_main_coords,font=\sffamily]
\begin{scope}[ spy using outlines={rectangle,color=purple,magnification=2,size=4cm,connect spies}]
    %Set up plane and lattice points
    \coordinate (Shift) at (2,2,0.5);
    \tdplotsetrotatedcoordsorigin{(Shift)}
    \begin{scope}[tdplot_rotated_coords,on background layer]
        % plane
        \draw[fill=blue,opacity=0.2] (0,-2,4) -- (0,2,4) -- (0,2,0) -- (0,-2,0) -- cycle;
        \coordinate (Q) at (0,1,1.414);
        \coordinate (P) at (0,-1,1.414);
        % Red lattice points
        \path[save path=\circleQ] (Q) circle[radius=4pt];
        \path[save path=\circleP] (P) circle[radius=4pt];
    \end{scope}

    \tdplotsetrotatedcoords{90}{90}{135}
    \tdplotsetrotatedcoordsorigin{ (Q) }
    \begin{scope}[tdplot_rotated_coords]

        \def\x{0.3}

        \coordinate (h11) at (\x, -\x, 0);
        \coordinate (h12) at (-\x, \x, 0);
        \coordinate (h21) at (\x, 0, -\x);
        \coordinate (h22) at (-\x, 0, \x);
        \coordinate (h31) at (0, \x, -\x);
        \coordinate (h32) at (0, -\x, \x);

        \coordinate (h'11) at (\x, \x, -2*\x);
        \coordinate (h'12) at (-\x, -\x, 2*\x);
        \coordinate (h'31) at (2*\x, -\x, -\x);
        \coordinate (h'32) at (-2*\x, \x, \x);
        \coordinate (h'21) at (\x, -2*\x, \x);
        \coordinate (h'22) at (-\x, 2*\x, -\x);


        % red hexagon half1
        \fill[fill=red!50!blue,opacity=0.5] (h11) -- (h21) --  (\x/2,\x/2,-\x) -- (-\x/2, -\x/2, \x) -- (h32) -- cycle; 
        % red hexagon half2
        \fill[fill=red,opacity=0.5] (h12) -- (h31) --  (\x/2,\x/2,-\x) -- (-\x/2, -\x/2, \x) --  (h22) -- cycle; 
        % green hexagon half1
        \fill[fill=green!50!blue,opacity=0.5] (h'11) -- (h'31) -- (h'21) -- (h'12) -- cycle;
        % green hexagon half2
        \fill[fill=green!70!gray,opacity=0.5](h'11) -- (h'22) -- (h'32) -- (h'12) -- cycle; 
        % black arrows
        \draw[ color=black] (h12) -- (Q); \draw[densely dotted,->, -stealth] (Q) -- (h11) node[right=-2pt] {\tiny $\tau_1$};
        \draw (Q) -- (h22); \draw[densely dotted, ->,-stealth, color=black] (Q) -- (h21) node[above=-1pt] {\tiny $\tau_2$};
        \draw[ color=black] (h31) -- (Q); \draw[densely dotted,->,-stealth] (Q) -- (h32) node[right=-2pt ] {\tiny $\tau_3$};
        % white arrows
        \draw[->, -stealth,dashed, color=white] (h'12) -- (h'11) node[left=-1pt] {\tiny $\tau'_1$};
        \draw[ dotted, color=white] (h'21) --  (Q); \draw[->, -stealth,color=white] (Q) -- (h'22) node[left=-1pt] {\tiny $\tau'_2$};
        \draw[ dotted, color=white] (h'31) -- (Q); \draw[->,-stealth,color=white] (Q) -- (h'32) node[below right=-3pt] {\tiny $\tau'_3$};

\end{scope}

\spy on (Q) in node[fill=blue,fill opacity=0.2] at (2,8,4); %
\end{scope}
\begin{scope}[on background layer]
\draw[fill=red,reuse path=\circleP];
\draw[fill=red,reuse path=\circleQ];
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

Note, however, that we have to add the background blue fill by hand. This is because spy and backgrounds make use of the same layer boxes.

| improve this answer | |
  • Thanks for the great answer! This has helped my understanding of scopes a lot. In my original question, I was wanting to have the hexagons invisible on the left (in the unmagnified section), and only visible in the spy view. But after considering your answer I think it is only possible to choose what is in the magnified view, not put things there that are not in the background (i.e. only see the hexagons in the spy lens). Is this correct? – user3264392 Apr 28 at 22:56
  • @user3264392 Oops, I misread the question. I think this is harder to achieve but I also do not quite understand the purpose. If it is only to appear in the zoomed frame, what prevents you from just using a scope in which you use scale=2, say? And you can definitely put this scope on top of the zoomed node. – user194703 Apr 28 at 23:14
  • My reasoning is as follows: My original image has more arrows and things in it than the example I have shown. The hexagons and arrows that I want to see in the magnified view will make the unmagnified view too complicated and busy. So I want to have a red dot in the unmagnified section, that when magnified shows the hexagons and arrows which is the 'fine structure' of the red dot. Using scale=2 will just make the hexagons bigger in the unmagnified image, won't it? Sorry for the confusion! – user3264392 Apr 29 at 1:04
  • @user3264392 Yes, this makes sense, but you can still just add these features on top of the spy node. – user194703 Apr 29 at 2:45

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.