是否可以用比率表示节点在axis
或环境中的位置?例如,对于任何的,都会放置在轴的中心。groupplot
\mynode{.5,.5}{$A$}
$A$
xmin,xmax,ymin,ymax
这将特别方便groupplots
,例如,如果我想在每个图表的右上角添加一个标签,这些图表具有不同的比例。
MWE 表明 $A$ 和 $B$ 没有相同的位置,因为轴具有不同的尺度和原点:
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\usetikzlibrary{matrix}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={
group name=myplot,
group size= 2 by 4},height=5cm,width=6.4cm]
\nextgroupplot[xmin=-2,xmax=3,ymin=-2,ymax=6]
\node at (axis cs:0.,0.) {$A$}; % line of interest
\nextgroupplot[xmin=-50,xmax=100,ymin=-100,ymax=50]
\node at (axis cs:0.,0.) {$B$}; % line of interest
\end{groupplot}
\end{tikzpicture}
\end{document}
代码的“感兴趣的线”应该改为类似的\mynode at (relative:0.2,0.2) {$A$}
(或者当然是其他语法),将节点放置在距左下角 20% 处。
答案1
正如我在评论中所说的那样,这里是在稍微改编的 MWE 中显示的两种可能性。
\documentclass[margin=5mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={
group name=myplot,
group size= 2 by 4,
},
height=5cm,
width=6.4cm,
]
\nextgroupplot[xmin=-2,xmax=3,ymin=-2,ymax=6]
% you have two choices to place stuff "relatively" in the plot
% which yield the same result on "normal" axis
\node at (axis description cs:0.2,0.2) {$A$};
\node at (rel axis cs:0.2,0.8) {$a$};
\nextgroupplot[xmin=-50,xmax=100,ymin=-100,ymax=50,
% but if you reverse the axis, the behavior can be adapted,
% depending on the value of `allow reversal of rel axis cs'
x dir=reverse,
allow reversal of rel axis cs=false,
]
\node at (axis description cs:0.2,0.2) {$B$};
\node at (rel axis cs:0.2,0.8) {$b$};
\end{groupplot}
\end{tikzpicture}
\end{document}