这个问题让我在过去 10-20 小时里抓狂不已。我有一个组图 (pgfplots),其中有两个图一个在另一个之下。我想画一条垂直线(例如 x=150e-6 处的帮助线),穿过所有图。
axis
在环境内绘图时,nextgroupplot
我可以使用类似这样的方法:\draw[thin] (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymax});
但这只允许我在其中一个子图上绘图。如果我超出轴环境,我可以在整个上绘图{tikzpicture}
,但我不能使用轴参考。
\begin{figure*}[h]
\centering
\begin{tikzpicture}
\begin{groupplot}[
group style = {group size=1 by 2, x descriptions at=edge bottom, vertical sep=0.2cm},
ytick={0, 1.8},
ymin=0,
ymax=3,
xmin=0,
xmax=550e-6,
change x base=true,
x SI prefix=micro]
\nextgroupplot
\addplot table [x index = {0}, y index = {1}, col sep=comma] {plots/plot1reduced.csv};
\nextgroupplot[x unit=s]
\addplot table [x index = {0}, y index = {3}, col sep=comma] {plots/plot1reduced.csv};
\draw[thin] (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs:150e-6,\pgfkeysvalueof{/pgfplots/ymax});
\end{groupplot}
\end{tikzpicture}
\caption{Case 1}
\label{fig:case1plot}
\end{figure*}
答案1
\coordinate
您可以在顶部和底部添加groupplot
,然后使用它们作为参考绘制线条。
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style = {group size=1 by 2, x descriptions at=edge bottom, vertical sep=0.2cm},
ytick={0, 1.8},
ymin=-3,
ymax=3,
xmin=0,
xmax=3]
\nextgroupplot
\addplot {x};
\coordinate (top) at (axis cs:1,\pgfkeysvalueof{/pgfplots/ymax});
\nextgroupplot[x unit=s]
\addplot {-x};
\coordinate (bot) at (axis cs:1,\pgfkeysvalueof{/pgfplots/ymin});
\end{groupplot}
\draw [thin] (top) -- (bot);
\end{tikzpicture}
\end{document}
答案2
你可以这样做
\draw[thick,red] (group c1r1.north) -- (group c1r2.south);
代码:
\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots,units}
\pgfplotsset{compat=1.11}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
group style = {group size=1 by 2, x descriptions at=edge bottom, vertical sep=0.2cm},
ytick={0, 1.8},
ymin=-3,
ymax=3,
xmin=0,
xmax=3]
\nextgroupplot
\addplot {x};
\nextgroupplot[x unit=s]
\addplot {-x};
\end{groupplot}
\draw[thick,red]
(group c1r1.north) -- (group c1r2.south);
\draw[thick,blue]
([xshift=-11mm]group c1r1.north) -- ([xshift=-11mm]group c1r2.south);
\end{tikzpicture}
\end{document}