I wonder if it is possible to draw parts of the images only in the maginfied node printed with \spy
?
\documentclass[
border=2cm,
]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,spy}
\tikzstyle{caption}=[%
green!70!black,
<->,
every node/.style={%
inner sep=3pt,fill=white,midway,sloped
}
]
\tikzstyle{hide}=[opacity=0]
\begin{document}
\begin{tikzpicture}[%
spy using outlines={circle, magnification=4, size=1.5cm, connect spies},
every spy in node/.style={hide/.style={opacity=1}};
]
\fill [gray] (0,0) rectangle (2,3);
\fill [hide,green] (0,0) circle (1pt);
% \tikzset{execute at begin scope={\tikzset{hide/.style={opacity=1}}}}
\spy on (0,0) in node at (-2,1);
\end{tikzpicture}
\end{document}
The green circle should only appear in the magnified part.
I tried to use the style hide
to hide an object in the main image and redefine hide
in the magnified part to become visible. But neither my every spy in node
way nor the execute at begin scope
way give any result.
Frédéric’s solution works fine for the simple case where the object to draw lies in the center of the spy node but it doesn’t care about the magnification (i.e. I must calculate the scale factor for the radius manually) and it doesn’t work with more complex images.
It would be great if I can access the (magnified/scaled) coordinates of the original image in the magnification. Here’s a second example showing why Frédéric’s solution won’t work …
\documentclass[
border=2cm,
]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,fit,spy}
\tikzstyle{caption}=[%
green!70!black,
<->,
every node/.style={%
inner sep=3pt,fill=white,midway,sloped
}
]
\tikzstyle{hide}=[opacity=0.2]% set to 0.2 to make it visible while testing
\begin{document}
\begin{tikzpicture}[%
spy using outlines={circle, magnification=4, size=1.5cm, connect spies},
every spy in node/.style={hide/.style={opacity=1}};
]
\fill [gray] (0,0) coordinate (A) rectangle (2,3);
\fill [hide,green] ($(A) + (0.02,0.05)$) circle (1pt);
% \tikzset{execute at begin scope={\tikzset{hide/.style={opacity=1}}}}
\spy on (0,0) in node at (-2,1);
\end{tikzpicture}
\end{document}