当我在具有不同轴刻度的另一个环境中使用坐标时,如何保持坐标的位置?
在示例中,我希望\node [...] at (c);
右图中的位于红点的位置,而不是使用轴比例缩放 y 坐标。
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}[x=0, y=0]
\begin{axis}[
xmin=0,
xmax=1,
ymin=0,
ymax=1
]
\node (c) at (0.6,0.8){};
\node [circle,inner sep=2pt,fill=white,draw] at (c) {};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[x=0, y=0]
\begin{axis}[
xmin=0,
xmax=1,
ymin=0,
ymax=10
]
\node [circle,inner sep=2pt,fill=white,draw] at (c) {};
\node [circle,inner sep=2pt,draw,red] at (0.6,0.8) {};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
最简单的方法是定义坐标的宏并重复使用它:
代码:
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}
\newcommand*{\SpecialPoint}{0.6,0.8}
\begin{document}
\begin{tikzpicture}[x=0, y=0]
\begin{axis}[
xmin=0,
xmax=1,
ymin=0,
ymax=1
]
\node [circle,inner sep=2pt,fill=white,draw] at (\SpecialPoint) {};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[x=0, y=0]
\begin{axis}[
xmin=0,
xmax=1,
ymin=0,
ymax=10
]
\node [circle,inner sep=2pt,fill=blue,draw,overlay] at (\SpecialPoint) {};
\node [circle,inner sep=2pt,draw,red] at (0.6,0.8) {};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
您应该将点定义为所有轴之外的点,与所用的轴无关。由于(c)
是坐标,因此您可以简单地将其定义为\def\Pointc{0.6,0.8}
。
\documentclass{standalone}
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\def\Pointc{0.6,0.8}
\begin{tikzpicture}[x=0, y=0]
\begin{axis}[
xmin=0,
xmax=1,
ymin=0,
ymax=1
]
\node [circle,inner sep=2pt,fill=white,draw] at (\Pointc) {};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}[x=0, y=0]
\begin{axis}[
xmin=0,
xmax=1,
ymin=0,
ymax=10
]
\node [circle,inner sep=2pt,fill=blue,draw] at (\Pointc) {};
\node [circle,inner sep=2pt,draw,red] at (0.6,0.8) {};
\end{axis}
\end{tikzpicture}
\end{document}