pgfplots
提供groupplots
图书馆(第 5.8 章),非常棒!- 我想在情节之间画一些线。
group c1r1.center
使用类似等的方法已经可以实现这一点。
- 问题:我想访问
axes cs
图的坐标系,以便我可以在特定数据点之间画线。 - 问题:是否可以使用
axes cs
坐标系在绘图之间绘制线条?在提供的 MWE 中,以下行是我尝试这样做的:\draw [thick, green] (myGroupName c1r2, axis cs:0.5,0.5) node {12} -- (myGroupName c2r2.center) node {22};
。这应该会生成与黄线相同的线。
\documentclass[border = 5pt, multi = {tikzpicture}]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
% pgfplots manual: 5.8 Grouping plots
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}[]
\begin{groupplot}[
group style = {
group size = 2 by 2,
group name = myGroupName,
},
height = 3.5cm,
width = 3.5cm,
/tikz/font = \small,
]
%% Plots
% Plot 1
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
% Plot 2
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
% Plot 3
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
% Plot 4
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\end{groupplot}
%
%% Annotations
\draw [thick, red] (myGroupName c1r1.center) node {11} -- (myGroupName c2r1.center) node {21};
% Works
\draw [thick, yellow] (myGroupName c1r2.center) node {12} -- (myGroupName c2r2.center) node {22};
% Does NOT work
%\draw [thick, green] (myGroupName c1r2 axis cs:0.5,0.5) node {12} -- (myGroupName c2r2.center) node {22};
\end{tikzpicture}
% Taken from page 458 from the
% pfgplots manual (Revision 1.18.1 (2021/05/15)).
\begin{tikzpicture}[shorten >=4pt,shorten <=4pt]
\begin{groupplot}[group style={group size=2 by 2},
height=3.5cm,width=3.5cm,/tikz/font=\small]
\nextgroupplot%1
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot%2
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot%3
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot%4
\addplot coordinates {(0,1) (1,0)};
\end{groupplot}
\draw [thick,>=latex,->,red]
(group c1r1.center) node {1.} --
(group c2r1.center) node {2.};
\draw [thick,>=latex,->,red]
(group c2r1.center) --
(group c1r2.center) node {3.};
\draw [thick,>=latex,->,red]
(group c1r2.center) --
(group c2r2.center) node {4.};
\end{tikzpicture}
\end{document}
答案1
我不知道是否可以在组图中从外部访问坐标系。通常这是不可能的,使用命名坐标的标准方法在这里也有效:
\documentclass[border=5pt, multi={tikzpicture}]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style={group size=2 by 2, group name=myGroupName},
height=3.5cm, width=3.5cm,
/tikz/font = \small,
]
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\coordinate (a) at (0.5,0.5);
\nextgroupplot
\addplot coordinates {(0,1) (1,0)};
\coordinate (b) at (0.5,0.5);
\end{groupplot}
\draw [thick, red] (myGroupName c1r1.center) node{11} -- (myGroupName c2r1.center) node{21};
%\draw [thick, yellow] (myGroupName c1r2.center) node{12} -- (myGroupName c2r2.center) node{22};
\draw [thick, green] (a) node{12} -- (b) node{22};
\end{tikzpicture}
\end{document}