编辑

编辑

我想在图形上创建缩放视图。由于缩放部分不仅包含缩放区域,还包含其他元素,因此我不使用spy库。这是一个 MWE。在环境无法在其外部被识别。这会导致错误。我怎样才能使它们成为全局的?

\documentclass[12pt]{standalone}

\usepackage{pgfplots}

\tikzset{every picture/.append style={remember picture}}

\begin{document}

\begin{tikzpicture}

\begin{axis}[%
width=4cm,
height=4cm,
scale only axis,
xmin=0,
xmax=150,
ymin=0,
ymax=150,
axis x line*=bottom,
axis y line*=left
]

% Draw the zoom box
\draw [draw=red, thick] (axis cs: 133,100) rectangle (axis cs:149,114);
% Define nodes, being the first end points of two lines
\node (topleftAxis1) at (axis cs: 133,114) {};
\node(bottomleftAxis1) at (axis cs: 133,100) {};
\end{axis}


\begin{axis}[%
width=4cm,
height=4cm,
at={(6cm,0cm)},
scale only axis,
xmin=133,
xmax=149,
ymin=100,
ymax=114,
]
% Define nodes, being the second end points of two lines
\node (topleftAxis2) at (axis cs: 133,114) {};
\node (bottomleftAxis2) at (axis cs: 133,100) {};
\end{axis}

% Draw the lines (error happens here)
\draw [draw=red, thick] (topLeftAxis1) -- (topLeftAxis2);
\draw [draw=red, thick] (bottomLeftAxis1) -- (bottomLeftAxis2);

\end{tikzpicture}

\end{document}

编辑

从帖子下方的评论来看,这种行为是由拼写错误引起的。顺便说一句,使用coordinate而不是node解决了线条不从节点发出的问题。因此,第一和第二轴环境中的定义应该是

\coordinate (topLeftAxis1) at (axis cs: 133,114);
\coordinate (bottomLeftAxis1) at (axis cs: 133,100);

\coordinate (topLeftAxis2) at (axis cs: 133,114);
\coordinate (bottomLeftAxis2) at (axis cs: 133,100);

分别。

相关内容