具有不同水平尺度的垂直堆叠组图

具有不同水平尺度的垂直堆叠组图

我有 4 个数据集,我想使用pgfplots'groupplot库将它们作为堆栈呈现。我遇到的问题是第一个数据集的水平范围比其余三个数据集大。我想最小化每个数据集的范围,以便最清楚地显示我的数据,这意味着对所有图表使用第一个数据集的较大范围对我来说是不可接受的。

我的问题是:如何x tick labels在第一个图表和最后一个图表下显示相关内容,而不在第二个和第三个图表下显示?MWE 如下。

\documentclass{standalone}

\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}

\pgfplotsset{
  cycle list={
    {black,thin},
  },
  /pgf/text mark/style={mark=none},
}

\begin{tikzpicture}
  \begin{groupplot}[
      group style={
        group name=my plots,
        group size=1 by 4,
        xlabels at=edge bottom,
        xticklabels at=edge bottom,
        vertical sep=5pt
      },
      footnotesize,
      xmin=0, xmax=90,
      ymin=0, ymax=7
.0,
      xtick={0,5,...,100},
      ytick={0,0.5,...,7.0},
      minor x tick num=4,
      minor y tick num=4,
    ]

    \nextgroupplot[ytick={0,1,...,7}]
    \addplot coordinates { (0.1,6.9) (44.5,4.8) (89.9,0.01) };

    \nextgroupplot[xmin=35,xmax=70,ymax=1.7]
    \addplot coordinates { (35.1,1.6) (55.2,1.3) (69,0.01) };

    \nextgroupplot[xmin=35,xmax=70,ymin=0.5,ymax=2.1]
    \addplot coordinates { (35.1,1.8) (69,1.6) };

    \nextgroupplot[xmin=35,xmax=70,ymax=1.1]
    \addplot coordinates { (35.1,0.75) (69,0.75) };

  \end{groupplot}
\end{tikzpicture}

\end{document}

答案1

子图之间间距更好的另一个答案:

\documentclass{standalone}

\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}

\pgfplotsset{
  cycle list={
    {black,thin},
  },
  /pgf/text mark/style={mark=none},
}

\begin{tikzpicture}
  \begin{groupplot}[
      group style={
        group name=my plots,
        group size=1 by 4,
        vertical sep=2pt
      },
      footnotesize,
      xmin=0, xmax=90,
      ymin=0, ymax=7
.0,
      %xtick={0,5,...,100},
      ytick={0,0.5,...,7.0},
      minor x tick num=4,
      minor y tick num=4,
    ]

    \nextgroupplot[ytick={0,1,...,7}]
    \addplot coordinates { (0.1,6.9) (44.5,4.8) (89.9,0.01) };

    \nextgroupplot[xmin=35,xmax=70,ymax=1.7, xticklabels=\empty, yshift=-1em]
    \addplot coordinates { (35.1,1.6) (55.2,1.3) (69,0.01) };

    \nextgroupplot[xmin=35,xmax=70,ymin=0.5,ymax=2.1, xticklabels=\empty]
    \addplot coordinates { (35.1,1.8) (69,1.6) };

    \nextgroupplot[xmin=35,xmax=70,ymax=1.1]
    \addplot coordinates { (35.1,0.75) (69,0.75) };

  \end{groupplot}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案2

您可以制作xtick=\empty第二和第三张图,并明确给出第一张和最后一张图。禁用

     xlabels at=edge bottom,
     xticklabels at=edge bottom,

顺便提一句。

代码:

\documentclass{standalone}

\usepackage{pgfplots}
\usetikzlibrary{pgfplots.groupplots}

\begin{document}

\pgfplotsset{
  compat=1.12,
  cycle list={
    {black,thin},
  },
  /pgf/text mark/style={mark=none},
}

\begin{tikzpicture}
  \begin{groupplot}[
      group style={
        group name=my plots,
        group size=1 by 4,
        %xlabels at=edge bottom,
%        xticklabels at=edge bottom,
        vertical sep=12pt
      },
      footnotesize,
      xmin=0, xmax=100,
      ymin=0, ymax=7
.0,
      xtick={0,5,...,100},
      ytick={0,0.5,...,7.0},
      minor x tick num=4,
      minor y tick num=4,
    ]

    \nextgroupplot[ytick={0,1,...,7},xtick={0,20,...,100}]
    \addplot coordinates { (0.1,6.9) (44.5,4.8) (99.9,0.01) };

    \nextgroupplot[xmin=35,xmax=70,ymax=1.7,xtick=\empty]
    \addplot coordinates { (35.1,1.6) (55.2,1.3) (69,0.01) };

    \nextgroupplot[xmin=35,xmax=70,ymin=0.5,ymax=2.1,xtick=\empty]
    \addplot coordinates { (35.1,1.8) (69,1.6) };

    \nextgroupplot[xmin=35,xmax=70,ymax=1.1]
    \addplot coordinates { (35.1,0.75) (69,0.75) };

  \end{groupplot}
\end{tikzpicture}

\end{document}

在此处输入图片描述

我已将其更改vertical sep为适应第一个图表下的标签。

相关内容