I am continuing the example I started here, and want to have two images in one picture being positioned relative to each other and using two scopes for the ´spies´. The following MWE includes a first way (without scopes) where I define the coordinate and spy node by own calculations. But i would like to use a scope like in the second example, in order to be independent of the image size i choose (I would have to change every .24\textwidth in the first picture). Adressing relatively to the image (being in [0,1]^2) would be quite preferable I think. Nevertheless, the second example does not work as expected, even more, it does not seem to follow a rule I could see.
In short I want a result as the first image using scopes as in the second example.
What am I doing wrong in the second, scope based, approach?
\documentclass{scrartcl}
\usepackage{amsmath, amsthm, amssymb}
\usepackage{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{environ,ifthen,tikz,pgfplots}
\usetikzlibrary{shadings,spy,calc}
\begin{document}
What i have\\
\begin{tikzpicture}[spy using outlines={circle,size=.1\textwidth, magnification=3, connect spies}]
% image 1
\node[anchor=south west,inner sep=0pt,label={270:{(a) Image 1}}] (image1) %
at (-.375\textwidth,0) {% Dummy image 1
\begin{tikzpicture}
\path [top color=blue, bottom color=black]
(0,0) rectangle (.24\textwidth,.24\textwidth);
\end{tikzpicture}};
\node (spy1) at ($ (image1.south west) + (350/512*.24\textwidth,380/512*.24\textwidth) $) {};
\coordinate (spy1to) at ($ (image1.center) + (-.03\textwidth,.23\textwidth) $);
\spy [black,thick] on (spy1) in node at (spy1to);%
% ---
\node[anchor=south west,inner sep=0pt,%
label={[align=left]270:{(b) Image 2.}}] %
(image2) at %
(-.125\textwidth,.125\textwidth) {%
\begin{tikzpicture}
\path [top color=green, bottom color=black]
(0,0) rectangle (.24\textwidth,.24\textwidth);
\end{tikzpicture}};
\node (spy1a) at %
($ (image2.south west) + (350/512*.24\textwidth,380/512*.24\textwidth) $) {};
\coordinate (spy1ato) at ($ (image2.center) + (-.18\textwidth,.065\textwidth) $);
\spy [black,thick] on (spy1a) in node at (spy1ato);%
\end{tikzpicture}
What i would like to have but it does not work
\begin{tikzpicture}[spy using outlines={circle,size=.1\textwidth, magnification=3, connect spies}]
% image 1
\node[anchor=south west,inner sep=0pt,label={270:{(a) Image 1}}] (image1) %
at (-.375\textwidth,0) {% Dummy image 1
\begin{tikzpicture}
\path [top color=blue, bottom color=black]
(0,0) rectangle (.24\textwidth,.24\textwidth);
\end{tikzpicture}};
\begin{scope}[x={(image1.south west)}, y={(image1.north east)}] % [0,0] - [1,1] as scope of the image
\node (spy1n) at (350/512,380/512) {};%relative pixel
\coordinate (spy1nto) at (-.5,1);
\spy [black,thick] on (spy1n) in node at (spy1nto);%
\end{scope}
% ---
\node[anchor=south west,inner sep=0pt,%
label={[align=left]270:{(b) Image 2.}}] %
(image2) at %
(-.125\textwidth,.125\textwidth) {%
\begin{tikzpicture}
\path [top color=green, bottom color=black]
(0,0) rectangle (.24\textwidth,.24\textwidth);
\end{tikzpicture}};
\begin{scope}[x={(image2.south west)}, y={(image2.north east)}] % [0,0] - [1,1] as scope of the image
\node (spy2) at (350/512,380/512) {};%relative pixel
\coordinate (spy2to) at (.5,1);
\spy [black,thick] on (spy2) in node at (spy2to);%
\end{scope}
\end{tikzpicture}
\end{document}
Resulting Document

Edit: As @cfr pointed out: Of course it is not a good idea to nest tikzpictures, I only did that here to get images to \spy on, in general the image-nodes contain .pngs, which is also my purpose in relative adressing, i.e.(350/512,380/512) is of course a pixel in an 512x512image.




tikzpictureenvironments when possible as it can cause problems. (Not the problem here. Just in general.) It would also be much simpler in this case to just use nodes rather than nodes containing pictures containing paths. – cfr Nov 27 '14 at 17:31\includegraphicsing in theimage-nodes of course in that node, which I wanted to avoid for the MWE. – Ronny Nov 27 '14 at 17:39tikzpictureeither. – cfr Nov 27 '14 at 18:57(-.5,1), say is relative to the512x512coordinate system because it is in the same scope as the part you are magnifying. (I'm not sure why it comes out to the right, rather than to the left of the picture, but it is centred in line with the top of the picture, which seems to be what you should expect?) – cfr Nov 27 '14 at 22:19image.south westshould reveal(0,0)for both scopes (w.r.t the corr. image) and...north eastthe point(1,1). Then,(-.5,1)states, that the center of the spy magnifier should be at the right border 1/2 (of the image) above the top border. So it's not precisely the placement as in the first example; which it does not (and i really don't know why). Fiddled around with that quite a while. The blue one in the first example should roughly(.25, -.5)in relative coordinates i think, the green one(-.25,.75). – Ronny Nov 27 '14 at 22:30-.5thexcoordinate? The1is giving theycoordinate and that matches - the magnifier is centred on the top image border. – cfr Nov 27 '14 at 22:34