访问 tikzpictures axis-environment 的参数

访问 tikzpictures axis-environment 的参数

假设我在 tikzpicture 的轴环境中定义了一个参数、坐标、节点或类似内容,并且我想访问它们。参见例如:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\begin{axis}[<parameters>]
  \def\V{5};
  (0,0) node[color=red](node){Node};
\end{axis}
(0,\V) node[color=red](node2){Node2};
\end{tikzpicture}

\end{document}

是否有某种访问修饰符(即全局/公共),以便我可以使用\Vnode 外部轴环境?

评论:我知道,我可以在轴环境之外定义它们,并在轴内访问它们,但我正在计算交点,使用\path [name intersections={of=function1 and function2,by=intersection}];,请参阅路口,所以这不是一个选项。感谢您的帮助,我们深表感谢。

答案1

欢迎来到 TeX.SE!我可能不明白你的问题。这是代码的可编译版本,其中外部节点是相对于轴内的节点绘制的。

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\begin{axis}%[xmin=0,xmax=1]
  \xdef\V{5};
  \path (0,0) node[color=red] (node) {Node};
  \addplot[draw=none] {x}; % needed to make pgfplots draw the node
\end{axis}
\path ([yshift=\V*1cm]node) node[color=red](node2){Node2};
\end{tikzpicture}

\end{document}

在此处输入图片描述

这是你想要的吗?如果不是,你能用不同的方式解释吗?(请注意,我更正了示例中节点的语法。)

相关内容