# Problem

I copied some code from here and here and combined the best parts for my work. I am wondering why the coordinates for my rectangle are in percentages of the image while the coordinates of the spy glass are not.

# Working Example

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[spy using outlines={circle,red,magnification=5,size=1.5cm, connect spies}]
\node [anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=10cm]{tux}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
\spy on (4.5,7) in node [] at (3,5);
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{document}


## Second Attempt

In this example, I tried putting the spy using outlines={circle,red,magnification=5,size=1.5cm, connect spies} within the \begin{scope} parameters, but this does not work. The image is zoomed at the wrong location. My idea came from the pgfmanual (68 Spy Library: Magnifying Parts of Pictures p.746 of v.3.0.0), but alas! It did not work.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[]
\node [anchor=south west,inner sep=0] (image) at (0,0) {\includegraphics[height=10cm]{tux}};
\begin{scope}[x={(image.south east)},y={(image.north west)},spy using outlines={circle,red,magnification=5,size=1.5cm, connect spies}]
\draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
\spy on (4.5,7) in node [] at (3,5);
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{document}

• \spy use the coordinate system in the scope of the spy using outlines option. – Paul Gaborit Dec 23 '14 at 14:48
• @PaulGaborit That is great that you identified the problem. I would like to find a way to give the spy glass the same scope as the image. – Jonathan Komar Dec 23 '14 at 15:17
• @macmadness86 sorry I can't understand your question to PaulGaborit. You can set the spy magnification by magnification=, or may be you want a specific unit and not a ratio ? – Kpym Dec 23 '14 at 15:52
• According to Paul Gaborit, the scope for spy is different than the one I explicitly specified with the \begin{scope} environment. I would like to have the spy glass respect my scope from image.south east to image.north west. This enables me to use percentage coordinates for drawing on the image. I can do this with the rectangle shape, but not with the spy glass. Why would I do this? I can then scale the image later without worrying about my nodes becoming misaligned. – Jonathan Komar Dec 23 '14 at 16:32

\spy uses the coordinate system in the scope of the spy using outlines option. To use your special coordinate system for spying your picture, you may define named coordinates.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{spy}
\begin{document}

\begin{tikzpicture}[spy using outlines={circle,red,magnification=3,size=2.5cm, connect spies}]
\node [anchor=south west,inner sep=0] (image)
at (0,0) {\includegraphics[height=10cm]{example-image}};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\draw[red,ultra thick,rounded corners] (0.62,0.65) rectangle (0.78,0.75);
\coordinate (pos spy) at (.2,.2);
\coordinate (center) at (.5,.5);
\spy on (center) in node [] at (pos spy);
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1,1);
\foreach \x in {0,1,...,9} { \node [anchor=north] at (\x/10,0) {0.\x}; }
\foreach \y in {0,1,...,9} { \node [anchor=east] at (0,\y/10) {0.\y}; }
\end{scope}
\end{tikzpicture}
\end{document}