我使用矩阵来排列和对齐组图中的图(如上所述这里) 并且我想创建一个具有一个子图的组图,该子图的大小例如为两个子图,如下所示。
我编写了以下 LaTeX 代码,正在寻找一个允许我将图形扩展为两个矩阵元素的选项。
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\matrix[row sep=0.01\textwidth, column sep=0.01\textwidth] {
\begin{axis}[xtick=\empty,height=2cm,width=0.245\textwidth, scale only axis]
\addplot {rnd};
\end{axis}
\pgfresetboundingbox
\path
(current axis.south west)
rectangle (current axis.north east);
&
\\
\begin{axis}[height=2cm,width=0.245\textwidth,scale only axis]
\addplot {rnd};
\end{axis}
\pgfresetboundingbox
\path
(current axis.south west)
rectangle (current axis.north east);
&
\begin{axis}[yticklabel pos=right,height=4cm+0.01\textwidth,width=0.245\textwidth, scale only axis]
\addplot {rnd};
\end{axis}
\pgfresetboundingbox
\path
(current axis.south west)
rectangle (current axis.north east);
\\
};
\end{tikzpicture}
\end{document}
答案1
这是使用该库的建议groupplots
。它不直接支持此类构造,因此我使用 垂直移动最终子图yshift
。最终子图的高度是根据其他子图的高度和它们之间的距离计算得出的。
\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro\plotw{3cm} % width of subplots
\pgfmathsetmacro\ploth{2cm} % height of smaller subplots
\pgfmathsetmacro\vsep{5pt} % vertical separation between subplots
\pgfmathsetmacro\hsep{5pt} % horizontal separation between subplots
\begin{groupplot}[
group style={
group size=2 by 2,
vertical sep=\vsep,
horizontal sep=\hsep,
x descriptions at=edge bottom},
height=\ploth,
width=\plotw,
scale only axis]
\nextgroupplot
\addplot [blue] {rnd};
\nextgroupplot[group/empty plot]
% second plot should be empty
\nextgroupplot
\addplot [red] {rnd};
\nextgroupplot[
yticklabel pos=right,
height=2*\ploth + \vsep,
yshift=\ploth+\vsep]
\addplot [green] {rnd};
\end{groupplot}
\end{tikzpicture}
\end{document}
答案2
因为我们还不能嵌套 pgf 矩阵,所以我建议采用以下解决方案:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tabular}{ll}
\begin{tabular}[b]{l}
\begin{tikzpicture}
%\matrix[row sep=0.01\textwidth, column sep=0.01\textwidth] {
\begin{axis}[xtick=\empty,height=2cm,width=0.245\textwidth, scale only axis]
\addplot {rnd};
\end{axis}
\pgfresetboundingbox
\path
(current axis.south west)
rectangle (current axis.north east);
%&
\end{tikzpicture}
\\
\begin{tikzpicture}
\begin{axis}[height=2cm,width=0.245\textwidth,scale only axis]
\addplot {rnd};
\end{axis}
\pgfresetboundingbox
\path
(current axis.south west)
rectangle (current axis.north east);
\end{tikzpicture}
\end{tabular}
&
\begin{tikzpicture}
\begin{axis}[yticklabel pos=right,height=4cm+0.01\textwidth,width=0.245\textwidth, scale only axis]
\addplot {rnd};
\end{axis}
\pgfresetboundingbox
\path
(current axis.south west)
rectangle (current axis.north east);
\end{tikzpicture}
\end{tabular}
\end{document}