创建非标准绘图数组

创建非标准绘图数组

我正在尝试使用 pgfplots 制作一个包含两列的图,第一列包含三个图,第二列仅包含一个图。在网上查看 group-plots 文档后,我惊讶地发现什么都没有找到。我本来想制作一个嵌套的 groupplot,但我想先看看是否有更好的方法。有什么想法吗?

答案1

@Zarko 谢谢你的建议!

这是我的 MWE

\documentclass[draft=on]{scrbook}
\usepackage{blindtext}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}

\begin{document}

\begin{figure}

\begin{minipage}[b]{0.45\linewidth}
\centering
\begin{tikzpicture}
\begin{groupplot}[group style={group name = myplot, group size = 1 by 4},height = 5cm, width = \linewidth]

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\end{groupplot}  % end

\end{tikzpicture}
\end{minipage}% Do not skip a line between minipages. Otherwise, it will place the figures one below the other.
\begin{minipage}[b]{0.45\linewidth}
\centering
\begin{tikzpicture}
\begin{axis}[height = 18cm, width = \linewidth]           
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};
\end{axis}
\end{tikzpicture}
\end{minipage}

\end{figure}

\end{document}

从而产生了这个在此处输入图片描述

答案2

这是一个仅使用一个的变体tikzpicture,其中包括一些技巧来计算前四个图的总高度,并将该高度用于最后一个图axis。 这样做的好处是,您可以确保第二列中轴的顶部与第一列中第一个轴的顶部对齐,底部与第一列中最后一个轴的底部对齐。

\documentclass[draft=on]{scrbook}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{calc} % required for the let syntax
\begin{document}

\begin{figure}
\centering
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group name = myplot,
    group size = 1 by 4
  },
  height = 5cm,
  width = 0.45\linewidth]

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\nextgroupplot[]
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};

\end{groupplot}  % end

% specify coordinate for top left of axis in second column
\coordinate (col2) at ([xshift=1.5cm]myplot c1r1.north east);
% calculate height of big axis
\path
let
\p1=(myplot c1r1.north), \p2=(myplot c1r4.south), \n1={\y1-\y2}
in
\pgfextra{%
\pgfmathsetlengthmacro{\tmp}{\n1}
\global\let\totalplotheight\tmp
};

\begin{axis}[
  at=(col2),
  % default anchor for axis is south west, we want north west
  anchor=north west,
  % we want the height to apply only to the axis box, not including labels, so add scale only axis
  scale only axis, 
  height = \totalplotheight,
  width = 0.45\linewidth
]           
\addplot[domain=-2*pi:2*pi, samples=100]{cos(deg(x))};
\end{axis}
\end{tikzpicture}

\end{figure}

\end{document}

代码输出

相关内容