如何从轴图坐标绘制一条线到轴环境之外的节点?
像这样:
\documentclass[margin=4mm, tikz]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[]
\node[name=MyNode, fill=yellow, draw, minimum size=22mm]{Node};
\begin{axis}[shift={(MyNode.south west)}, anchor=north west, yshift=-6mm,
ymin=0, ymax=5,
]
\addplot[thick, -|,] plot coordinates { (2,0) (2,3)} coordinate[](X);
\draw[red, thick, <->](X) -- (MyNode); % not nice
\end{axis}
\end{tikzpicture}
\end{document}
答案1
\draw
只需在环境之外使用该命令axis
:
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\node[fill=yellow, draw, minimum size=22mm] (MyNode) {Node};
\begin{axis}[
shift={(MyNode.south west)},
anchor=north west,
yshift=-6mm,
ymin=0, ymax=5,
]
\addplot[thick, -|] plot coordinates { (2,0) (2,3) } coordinate (X);
\end{axis}
\draw[violet, thick, ->] (MyNode) -- +(0,-1.5) -| (X)
node[pos=0.75, right] {this};
\end{tikzpicture}
\end{document}