我使用“父” tikzpicture 来实现比 groupplots 更灵活的 pgfplots 定位,即将 pgfplots 放在节点中,如以下 MWE 所示:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{positioning,calc}
\pgfplotsset{every axis/.append style={width=5cm}}
%\tikzstyle{every picture}+=[remember picture,overlay]
\begin{document}
\begin{tikzpicture}
\node (TL) {% Plot 1
\begin{tikzpicture}
\begin{axis}
\addplot coordinates { (-5,100) (115,10) };
\coordinate (C) at (axis cs: 0,0);
\end{axis}
\end{tikzpicture}
};
\node[right=1cm of TL] (TR) {% Plot 2
\begin{tikzpicture}
\begin{axis}
\addplot coordinates { (-5,-120) (15,100) };
\coordinate (D) at (axis cs: 0,0);
\end{axis}
\end{tikzpicture}
};
\node[anchor=north] (B) at ($(TL.south)!0.5!(TR.south)$) {% Plot 3
\begin{tikzpicture}
\begin{axis}
\addplot coordinates { (-5,100) (115,100) };
\end{axis}
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}
有没有办法用一条线连接坐标(C)
和(D)
?我尝试了这个remember picture, overlay
选项,但是没有用,图形的位置在页面的左上角。
答案1
如果添加该remember picture
选项,那么您可以在不同的tikzpicture
环境中访问这些节点:
笔记:
- 这只是为了展示如何使用
remember picture
选项然后连接节点。我不推荐嵌套tikzpicture
环境。
代码:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{positioning,calc}
\pgfplotsset{every axis/.append style={width=5cm}}
%\tikzstyle{every picture}+=[remember picture,overlay]
\begin{document}
\begin{tikzpicture}[remember picture]
\node (TL) {% Plot 1
\begin{tikzpicture}
\begin{axis}
\addplot coordinates { (-5,100) (115,10) };
\coordinate (C) at (axis cs: 0,0);
\end{axis}
\end{tikzpicture}
};
\node[right=1cm of TL] (TR) {% Plot 2
\begin{tikzpicture}[remember picture]
\begin{axis}
\addplot coordinates { (-5,-120) (15,100) };
\coordinate (D) at (axis cs: 0,0);
\end{axis}
\end{tikzpicture}
};
\node[anchor=north] (B) at ($(TL.south)!0.5!(TR.south)$) {% Plot 3
\begin{tikzpicture}
\begin{axis}
\addplot coordinates { (-5,100) (115,100) };
\end{axis}
\end{tikzpicture}
};
\end{tikzpicture}
%
\begin{tikzpicture}[remember picture,overlay]
\draw [thick, red] (C) -- (D);
\end{tikzpicture}%
\end{document}