我想使用叠加在两个 tikz 图之间画线。这是一个最小的例子:
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}
\begin{minipage}{0.49\textwidth}
\begin{tikzpicture}[scale=0.6, remember picture]
\pgfplotsset{scale only axis}
\begin{axis}[
axis lines=left,
samples=100,
ymax = 2.3]
\addplot[color = black][domain=0:2] {x};
\node[draw,black] (a) at (axis cs: 1, 1.5){};
\end{axis}
\end{tikzpicture}
\end{minipage}
\hfill
\begin{minipage}{0.49\textwidth}
\begin{tikzpicture}[scale=0.6,remember picture]
\definecolor{mathblue}{rgb}{0,0.28,0.55 }
\pgfplotsset{scale only axis}
\begin{axis}[
axis lines=left,
samples=100,
ymax = 2.3
]
\addplot[color = black][domain=0:2] {x};
\node[draw,black] (A) at (axis cs: 1,1.5 ) {};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{tikzpicture}[remember picture,overlay]
\draw[dashed,gray] (a) -- (A);
\end{tikzpicture}
\caption{test}
\end{figure}
\end{document}
但是,在输出中,(a) 和 (A) 之间的连接线完全处于错误的位置,我没有发现我的错误。任何建议都值得感激。
答案1
如果你真的需要使用scale
键,在轴中使用它,而不是在环境中tikzpicture
。
\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{figure}
\begin{minipage}{0.49\textwidth}
\begin{tikzpicture}[ remember picture]
\pgfplotsset{scale only axis}
\begin{axis}[scale=0.6,
axis lines=left,
samples=100,
ymax = 2.3]
\addplot[color = black][domain=0:2] {x};
\node[draw,black] (a) at (axis cs: 1, 1.5){};
\end{axis}
\end{tikzpicture}
\end{minipage}
\hfill
\begin{minipage}{0.49\textwidth}
\begin{tikzpicture}[remember picture]
\definecolor{mathblue}{rgb}{0,0.28,0.55 }
\pgfplotsset{scale only axis}
\begin{axis}[scale=0.6,
axis lines=left,
samples=100,
ymax = 2.3
]
\addplot[color = black][domain=0:2] {x};
\node[draw,black] (A) at (axis cs: 1,1.5 ) {};
\end{axis}
\end{tikzpicture}
\end{minipage}
\begin{tikzpicture}[remember picture,overlay]
\draw[dashed,gray] (a) -- (A);
\end{tikzpicture}
\caption{test}
\end{figure}
\end{document}
scale
一般来说,在 pgfplots 中不需要太多使用,您可以使用width
和height
键。