使用 TikZ spy 在放大的图片上添加箭头和文字

使用 TikZ spy 在放大的图片上添加箭头和文字

我想在放大图片上添加一些箭头和文字。在放大图片上添加 A、B 和 C。有人能帮我解决这个问题吗?谢谢在此处输入图片描述

    \begin{figure}
    \begin{tikzpicture}[scale=1,spy using outlines={circle, magnification=4,size=2.5cm, connect spies}]
    \coordinate (center) at (0,0);
    \coordinate (A) at (2,1.5);
    \coordinate (B) at (6,1.5);
    \coordinate (C) at (2,1);
    \coordinate (D) at (6,1);
    \coordinate (E) at (2,0);
    \coordinate (F) at (6,0);
    \coordinate (G) at (2,-1);
    \coordinate (H) at (6,-1);
    \coordinate (I) at (2,-1.5);
    \coordinate (J) at (6,-1.5);
    %Upper 
    \foreach \x / \y / \z in {3.9/1.5/K, 4.1/1.5/L, 3.9/1/M, 4.1/1/N,3.8/1.5/O, 3.8/1.3/P, 3.9/1.3/Q,  4.1/1.1/R, 4.2/1.1/S, 4.2/1.5/T}
    {\coordinate (\z) at (\x, \y);}
    \filldraw  (K)--(M)--(N)--(L)--(K);
    \draw (O)--(P)--(Q);
    \draw (R)--(S)--(T);
    %Lower 
    \foreach \x / \y / \z in {3.9/-1.5/K, 4.1/-1.5/L, 3.9/-1/M, 4.1/-1/N, 3.8/-1.5/O, 3.8/-1.3/P, 3.9/-1.3/Q,  4.1/-1.1/R, 4.2/-1.1/S, 4.2/-1.5/T}
    {\coordinate (\z) at (\x, \y);}
    \filldraw  (K)--(M)--(N)--(L)--(K);
    \draw (O)--(P)--(Q);
    \draw (R)--(S)--(T);
    %The left figure
    \draw [->] (-0.3,0.7) arc [start angle=150, end angle=30, radius=10pt];
    \draw (center) circle [radius=1.5cm];
    \draw (center) circle [radius=1cm];
    \foreach \x / \y in         {0/30,10/40,20/50,30/60,40/70,50/80,60/90,70/100,80/110,90/120,100/130,110/140,120/150,130/160,140/170,150/180,160/190,170/200,180/210,190/220,200/230,210/240,220/250,230/260,240/270,250/280,260/290,270/300,280/310,290/320,300/330,310/340,320/350,330/360,340/10,350/20}
    {\draw (\x:1) -- (\y:1.5);}
    %The right figure
    \draw (A)--(B);
    \draw (C)--(D);
    \draw (G)--(H);
    \draw (I)--(J);
    \draw (C) cos (1.86,0.5) sin (E);
    \filldraw [pattern=north east lines] (E) cos (2.14,-0.5) sin(G) cos (1.86,-0.5) sin (E);
    %\draw (E) cos (1.86,-0.5) sin (G);
    \draw (F) cos (6.14,-0.5) sin(H);
    \filldraw [pattern=north east lines](D) cos (6.14,0.5) sin (F) cos (5.86,0.5) sin (D);
    \draw [style=dashed] (-2,0)--(6.5,0) (0,2)--(0,-2);
    %located zoomed figure
    \spy [red] on (4,1.25) in node [spy] at (8,0);
    \end{tikzpicture}
    \end{figure}

答案1

这是其中一种方法。为了确保箭头停留在监视区域的顶部,我使用了库backgrounds。将箭头设为B绿色以证明它确实位于顶部。

在此处输入图片描述

\documentclass[tikz,margin=0.5cm]{standalone}
\usetikzlibrary{patterns,spy,backgrounds}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

    \begin{tikzpicture}[scale=1,spy using outlines={circle, magnification=4,size=2.5cm, connect spies}]
    \coordinate (center) at (0,0);
    \coordinate (A) at (2,1.5);
    \coordinate (B) at (6,1.5);
    \coordinate (C) at (2,1);
    \coordinate (D) at (6,1);
    \coordinate (E) at (2,0);
    \coordinate (F) at (6,0);
    \coordinate (G) at (2,-1);
    \coordinate (H) at (6,-1);
    \coordinate (I) at (2,-1.5);
    \coordinate (J) at (6,-1.5);
    %Upper 
    \foreach \x / \y / \z in {3.9/1.5/K, 4.1/1.5/L, 3.9/1/M, 4.1/1/N,3.8/1.5/O, 3.8/1.3/P, 3.9/1.3/Q,  4.1/1.1/R, 4.2/1.1/S, 4.2/1.5/T}
    {\coordinate (\z) at (\x, \y);}
    \filldraw  (K)--(M)--(N)--(L)--(K);
    \draw (O)--(P)--(Q);
    \draw (R)--(S)--(T);
    %Lower 
    \foreach \x / \y / \z in {3.9/-1.5/K, 4.1/-1.5/L, 3.9/-1/M, 4.1/-1/N, 3.8/-1.5/O, 3.8/-1.3/P, 3.9/-1.3/Q,  4.1/-1.1/R, 4.2/-1.1/S, 4.2/-1.5/T}
    {\coordinate (\z) at (\x, \y);}
    \filldraw  (K)--(M)--(N)--(L)--(K);
    \draw (O)--(P)--(Q);
    \draw (R)--(S)--(T);
    %The left figure
    \draw [->] (-0.3,0.7) arc [start angle=150, end angle=30, radius=10pt];
    \draw (center) circle [radius=1.5cm];
    \draw (center) circle [radius=1cm];
    \foreach \x / \y in         {0/30,10/40,20/50,30/60,40/70,50/80,60/90,70/100,80/110,90/120,100/130,110/140,120/150,130/160,140/170,150/180,160/190,170/200,180/210,190/220,200/230,210/240,220/250,230/260,240/270,250/280,260/290,270/300,280/310,290/320,300/330,310/340,320/350,330/360,340/10,350/20}
    {\draw (\x:1) -- (\y:1.5);}
    %The right figure
    \draw (A)--(B);
    \draw (C)--(D);
    \draw (G)--(H);
    \draw (I)--(J);
    \draw (C) cos (1.86,0.5) sin (E);
    \filldraw [pattern=north east lines] (E) cos (2.14,-0.5) sin(G) cos (1.86,-0.5) sin (E);
    %\draw (E) cos (1.86,-0.5) sin (G);
    \draw (F) cos (6.14,-0.5) sin(H);
    \filldraw [pattern=north east lines](D) cos (6.14,0.5) sin (F) cos (5.86,0.5) sin (D);
    \draw [style=dashed] (-2,0)--(6.5,0) (0,2)--(0,-2);
    %located zoomed figure
    \coordinate (zoomLoc) at (8,0);
    \spy [red] on (4,1.25) in node at (zoomLoc);

    \begin{pgfonlayer}{foreground}
    \draw [thick,<-] ([xshift=0.6cm,yshift=-0.3cm]zoomLoc)--++(-60:0.8cm)--++(0:0.7cm) node [right] {C};
    \draw [thick,<-] ([xshift=-0.6cm,yshift=0.5cm]zoomLoc)--++(70:1.2cm)--++(0:1.8cm) node [right] {A};
    \draw [green,thick,<-] ([xshift=0.3cm]zoomLoc)--++(70:1.2cm)--++(0:0.9cm) node [text=black,right] {B};
    \end{pgfonlayer}{foreground}

    \end{tikzpicture}
\end{document}

答案2

以下是基于的答案这个较旧的答案概念上非常类似于Milo 的回答很棒。这个答案的优点在于,它带有缩放部分的局部坐标系,这可能使注释的放置更加直接。特别是,如果您决定移动放大的内容和/或更改缩放系数,注释将会调整。Milos 方法也适用于移动放大的内容。为了获得更好的可见性,我还使用了轮廓箭头。

\documentclass[tikz,margin=0.5cm]{standalone}
\usetikzlibrary{patterns,spy,backgrounds,calc,arrows.meta}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}
\tikzset{every spy on node/.append style={alias=zoom}}
    \begin{tikzpicture}[remember picture,scale=1,spy using outlines={circle, magnification=4,size=2.5cm, connect spies}]
    \coordinate (center) at (0,0);
    \coordinate (A) at (2,1.5);
    \coordinate (B) at (6,1.5);
    \coordinate (C) at (2,1);
    \coordinate (D) at (6,1);
    \coordinate (E) at (2,0);
    \coordinate (F) at (6,0);
    \coordinate (G) at (2,-1);
    \coordinate (H) at (6,-1);
    \coordinate (I) at (2,-1.5);
    \coordinate (J) at (6,-1.5);
    %Upper 
    \foreach \x / \y / \z in {3.9/1.5/K, 4.1/1.5/L, 3.9/1/M, 4.1/1/N,3.8/1.5/O, 3.8/1.3/P, 3.9/1.3/Q,  4.1/1.1/R, 4.2/1.1/S, 4.2/1.5/T}
    {\coordinate (\z) at (\x, \y);}
    \filldraw  (K)--(M)--(N)--(L)--(K);
    \draw (O)--(P)--(Q);
    \draw (R)--(S)--(T);
    %Lower 
    \foreach \x / \y / \z in {3.9/-1.5/K, 4.1/-1.5/L, 3.9/-1/M, 4.1/-1/N, 3.8/-1.5/O, 3.8/-1.3/P, 3.9/-1.3/Q,  4.1/-1.1/R, 4.2/-1.1/S, 4.2/-1.5/T}
    {\coordinate (\z) at (\x, \y);}
    \filldraw  (K)--(M)--(N)--(L)--(K);
    \draw (O)--(P)--(Q);
    \draw (R)--(S)--(T);
    %The left figure
    \draw [->] (-0.3,0.7) arc [start angle=150, end angle=30, radius=10pt];
    \draw (center) circle [radius=1.5cm];
    \draw (center) circle [radius=1cm];
    \foreach \x / \y in         {0/30,10/40,20/50,30/60,40/70,50/80,60/90,70/100,80/110,90/120,100/130,110/140,120/150,130/160,140/170,150/180,160/190,170/200,180/210,190/220,200/230,210/240,220/250,230/260,240/270,250/280,260/290,270/300,280/310,290/320,300/330,310/340,320/350,330/360,340/10,350/20}
    {\draw (\x:1) -- (\y:1.5);}
    %The right figure
    \draw (A)--(B);
    \draw (C)--(D);
    \draw (G)--(H);
    \draw (I)--(J);
    \draw (C) cos (1.86,0.5) sin (E);
    \filldraw [pattern=north east lines] (E) cos (2.14,-0.5) sin(G) cos (1.86,-0.5) sin (E);
    %\draw (E) cos (1.86,-0.5) sin (G);
    \draw (F) cos (6.14,-0.5) sin(H);
    \filldraw [pattern=north east lines](D) cos (6.14,0.5) sin (F) cos (5.86,0.5) sin (D);
    \draw [style=dashed] (-2,0)--(6.5,0) (0,2)--(0,-2);
    %located zoomed figure
    \coordinate (zoomLoc) at (8,0);
    \spy [red,on background layer,
    spy connection path={\draw (tikzspyonnode) -- (tikzspyinnode);
    \begin{pgfonlayer}{foreground} % https://tex.stackexchange.com/a/426272/121799
    \begin{scope}[shift={(tikzspyinnode.south west)},x={($(tikzspyinnode.south east)-(tikzspyinnode.south west)$)},
    y={($(tikzspyinnode.north west)-(tikzspyinnode.south west)$)}]
     \draw[{Latex[open]}-,black,double=white] (0.15,0.75) -- ++ (0.5,0.5) -- ++ (0.5,0) 
     node[right,minimum size=0pt]{A};
     \draw[{Latex[open,fill=white]}-,black,double=white] (0.5,0.5) -- 
     ++ (0.35,0.35) -- ++ (0.35,0)  node[right,minimum size=0pt]{B};
     \draw[{Latex[open,fill=white]}-,black,double=white] (0.8,0.4) -- 
     ++ (0.25,-0.25) -- ++ (0.15,0)  node[right,minimum size=0pt]{C};
    \end{scope}
    \end{pgfonlayer}}] on (4,1.25) in node at (zoomLoc);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容