I want to access two spypoints in a tikzpicture
environment via node name. Unfortunately, naming the spypoint doesn't seem to work in the same way as it does for the magnifyglass node.
Here is my MWE:
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{spy}
\begin{document}
\begin{tikzpicture}
\begin{scope}[spy using outlines={rectangle, magnification=4, connect spies}]
\begin{axis}[%
height=5cm,%
width=10cm, %
ymin=-1, ymax=21, %
xmin=0, xmax=1000, %
xticklabels={},%
ytick={0, 10, 20}, %
name=first,%
]
\coordinate (spypoint1) at (axis cs:30,10);
\coordinate (magnifyglass1) at (axis cs:300,3.3);
\coordinate (spypoint2) at (axis cs:850,3.3);
\coordinate (magnifyglass2) at (axis cs:650,3.4);
\end{axis}
\begin{axis}[%
height=4cm,%
width=10cm, %
ymin=-1, ymax=1, %
xmin=0, xmax=1000, %
at={(first.below south west)}, yshift=-0.1cm, anchor=north west, %
]
\coordinate (spypoint3) at (axis cs:30,0);
\coordinate (magnifyglass3) at (axis cs:300,0.4);
\coordinate (spypoint4) at (axis cs:850,-0.1);
\coordinate (magnifyglass4) at (axis cs:600,-0.4);
\end{axis}
\spy [black, height=12mm, width=20mm, name=a1] on (spypoint1)
in node [fill=white,name=a] at (magnifyglass1);
\spy [black, height=12mm, width=22mm] on (spypoint2)
in node [fill=white,name=b] at (magnifyglass2);
\spy [black, height=12mm, width=20mm, name=c1] on (spypoint3)
in node [fill=white,name=c] at (magnifyglass3);
\spy [black, height=12mm, width=22mm] on (spypoint4)
in node [fill=white,name=d] at (magnifyglass4);
\end{scope}
\draw[dashed] (a) -- (b);
\draw[dashed] (c) -- (d);
\draw[red] (a1) -- (c1);
\end{tikzpicture}
\end{document}
As you can see, the connections for \draw (a) -- (b)
and (c) -- (d)
work fine, while the connection (a1) -- (c1)
doesn't work. I get the error message
No shape named a1 is known.
and the same for (c1)
.
Without the \draw[red] (a1) -- (c1);
line, the picture looks as follows. The red line resembles what my expected result of adding the line would be
Can anyone tell me the correct way to name the spypoint node? I didn't find anything in the pgfplots
or tikz
manual. Thank you in advance.
spypoint1
withspypoint3
? – Old Nick Aug 25 '16 at 11:25spypoint1
with the upper edges ofspypoint3
and the same forspypoint2
andspypoint4
. So I thought, if I could access the nodes via names, I could use something like\draw (spypoint1.south west) -- (spypoint3.north west)
. Unfortunately I already fail at naming thespypoint
nodes as it seems. – Alexander Schrodt Aug 25 '16 at 11:31pgfmanual
on page 741 (v3.0.1a) this should be possible using theevery spy on node
style. Does that help? – Stefan Pinnow Aug 25 '16 at 17:50