如何从 TikZ Spy 中排除项目

如何从 TikZ Spy 中排除项目

有点相关我想问排除从放大区域中移除项目。在下面的示例中,我不希望针线或橙色线出现在放大区域中。这可以吗?

梅威瑟:

\documentclass[tikz,11pt]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{spy}

\begin{filecontents}{data.dat}
X   Y
0   0
1   1
2   2
3   1
4   0
\end{filecontents}

\tikzstyle{every pin}=[fill=white,draw=black,font=\footnotesize,]
\tikzstyle{point} = [draw,circle,fill=black,scale=0.3]

\begin{document}
\begin{tikzpicture}[spy using outlines = {circle,magnification=6, connect spies}]
\begin{axis}
\addplot table {data.dat};
\node[point,red,pin=above left:P1] (P1) at (axis cs:0.5,0.5) {};
\node[point,cyan,pin=below right:P2] (P2) at (axis cs:0.52,0.52) {};
\node[point,pin=above right:P3] (P3) at (axis cs:2.5,1.5) {};
\node[point,pin=above right:P4] (P4) at (axis cs:3.5,1) {};
\coordinate (spypoint) at (0.5,0.5);
\coordinate (magnifyglass) at (0.5,1.5);

\spy [size=2cm] on (spypoint) in node[fill=white] at (magnifyglass);

\draw[thick,orange] (P1) -- (P2) -- (P3)--(P4);
\end{axis}
\end{tikzpicture}
\end{document}

平均能量损失

答案1

要做到这一点,您可以只监视一个范围,而不是整个图像。在这种情况下,在监视范围之外绘制的所有内容都不会出现在放大的区域中。

要在示波器后添加引脚,您可以使用node also

\documentclass[tikz,11pt]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{spy}

\begin{filecontents}{data.dat}
X   Y
0   0
1   1
2   2
3   1
4   0
\end{filecontents}

\tikzstyle{every pin}=[fill=white,draw=black,font=\footnotesize]
\tikzstyle{point}=[draw,circle,fill=black,scale=0.3]

\begin{document}
  \begin{tikzpicture}
    % you can spy in a scope
    \begin{scope}[spy using outlines = {circle,magnification=6, connect spies}]
      \begin{axis}
        \addplot table {data.dat};
        \node[point,red] (P1) at (axis cs:0.5,0.5) {}; % <-- remove the pin from here
        \node[point,cyan] (P2) at (axis cs:0.52,0.52) {}; % <-- remove the pin from here
        \node[point,pin=above right:P3] (P3) at (axis cs:2.5,1.5) {};
        \node[point,pin=above right:P4] (P4) at (axis cs:3.5,1) {};
        \coordinate (spypoint) at (0.5,0.5);
        \coordinate (magnifyglass) at (0.5,1.5);
        \spy [size=2cm] on (spypoint) in node[fill=white] at (magnifyglass);
      \end{axis}
    \end{scope}
    % drawing outside the spyed scope is not present in the spy node
    \node also [pin=above left:P1] (P1); % <-- add the pin later
    \node also [pin=below right:P2] (P2); % <-- add the pin later
    \draw[thick,orange] (P1) -- (P2) -- (P3)--(P4);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容