Somewhat related to this question, I would like to exclude items from the magnified area. In the example below, I do not want the pin lines or the orange line to appear in the magnified area. Is this possible?
MWE:
\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}