删除 groupplot 中的 xticks

删除 groupplot 中的 xticks

有没有办法去掉下面组图中第一和第二个图之间的 xticks 以及第二和第三个图之间的 xticks?去掉每个图内部的 xticks(例如从 0 向上延伸的刻度)就可以了。

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots, pgfplotstable}
\usepgfplotslibrary{groupplots}
\pgfplotstableread{
wk  1   2   3
0   2   3   4
1   5   6   7
2   0   0   0
3   5   6   7
}\data
\begin{document}
\begin{tikzpicture}
  \pgfplotsset{group/vertical sep={0cm},
    group/x descriptions at=edge bottom,
  }
  \begin{groupplot}[group style={group size=1 by 3},
                    height=5cm,
                    width=8cm,
                    ybar stacked,
                    xtick=data,
                    ymin=0,
                    xticklabels from table={\data}{wk},
                    tick align=outside
                    ]
    \nextgroupplot
      \addplot [fill=black!60] table [y=1, x expr=\coordindex] {\data};    
      \addplot [fill=black!20] table [y=2, x expr=\coordindex] {\data};
      \addplot [fill=black!40] table [y=3, x expr=\coordindex] {\data};
    \nextgroupplot
      \addplot [fill=black!60] table [y=1, x expr=\coordindex] {\data};    
      \addplot [fill=black!20] table [y=2, x expr=\coordindex] {\data};
      \addplot [fill=black!40] table [y=3, x expr=\coordindex] {\data};
    \nextgroupplot
      \addplot [fill=black!60] table [y=1, x expr=\coordindex] {\data};    
      \addplot [fill=black!20] table [y=2, x expr=\coordindex] {\data};
      \addplot [fill=black!40] table [y=3, x expr=\coordindex] {\data};
\end{groupplot}
\end{tikzpicture}
\end{document}

答案1

所以您正在寻找类似的东西?

% used PGFPlots v1.16
\documentclass[border=5pt]{standalone}
\usepackage{pgfplotstable}
\usepgfplotslibrary{groupplots}
    \pgfplotstableread{
        wk  1   2   3
        0   2   3   4
        1   5   6   7
        2   0   0   0
        3   5   6   7
    }\data
\begin{document}
\begin{tikzpicture}
    \begin{groupplot}[
        group style={
            group size=1 by 3,
            vertical sep={0cm},
            x descriptions at=edge bottom,
        },
        height=5cm,
        width=8cm,
        ybar stacked,
        xtick=data,
        ymin=0,
        xticklabels from table={\data}{wk},
        tick align=outside,
        table/x expr=\coordindex,
    ]
    \nextgroupplot[
        xtick pos=upper,
    ]
        \addplot [fill=black!60] table [y=1] {\data};
        \addplot [fill=black!20] table [y=2] {\data};
        \addplot [fill=black!40] table [y=3] {\data};

    \nextgroupplot[
        xtick style={
            /pgfplots/major tick length=0pt,
        },
    ]
        \addplot [fill=black!60] table [y=1] {\data};
        \addplot [fill=black!20] table [y=2] {\data};
        \addplot [fill=black!40] table [y=3] {\data};

    \nextgroupplot[
        xtick pos=lower,
    ]
        \addplot [fill=black!60] table [y=1] {\data};
        \addplot [fill=black!20] table [y=2] {\data};
        \addplot [fill=black!40] table [y=3] {\data};
\end{groupplot}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容