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 thespy using outlines
option.magnification=
, or may be you want a specific unit and not a ratio ?\begin{scope}
environment. I would like to have the spy glass respect my scope fromimage.south east
toimage.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.