在下面的组图中,x 值对于所有子图都是通用的。我希望 x 标签仅显示在组图的最后一行。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size= 2 by 2},height=6cm,width=5cm,ybar,xtick=data,tick label style={font=\footnotesize},x tick label style={rotate=45,anchor=east}
,symbolic x coords={metricA,metricB,metricC,metricD}]
\nextgroupplot[title=A1,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a1a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a1b-value,col sep=space]{foo.csv};
\nextgroupplot[title=A2,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a2a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a2b-value,col sep=space]{foo.csv};
\nextgroupplot[title=A3,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a3a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a3b-value,col sep=space]{foo.csv};
\nextgroupplot[title=A4,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a4a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a4b-value,col sep=space]{foo.csv};
\end{groupplot}
\end{tikzpicture}
\end{document}
foo.csv
metric a1a-value a1b-value a2a-value a2b-value a3a-value a3b-value a4a-value a4b-value
metricA 20 30 50 55 55 20 30 50
metricB 40 40 60 23 23 40 40 60
metricC 50 20 70 67 67 50 20 70
metricD 60 50 20 20 20 60 50 20
答案1
xticklabels at=edge bottom
作为group style
选项使用。
代码:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={
group size= 2 by 2
,xticklabels at=edge bottom % <- added
}
,height=6cm,width=5cm,ybar,xtick=data,tick label style={font=\footnotesize}
,x tick label style={rotate=45,anchor=east}
,symbolic x coords={metricA,metricB,metricC,metricD}]
\nextgroupplot[title=A1,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a1a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a1b-value,col sep=space]{foo.csv};
\nextgroupplot[title=A2,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a2a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a2b-value,col sep=space]{foo.csv};
\nextgroupplot[title=A3,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a3a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a3b-value,col sep=space]{foo.csv};
\nextgroupplot[title=A4,bar width=2pt]
\addplot[fill=blue] table[x=metric,y=a4a-value,col sep=space]{foo.csv};
\addplot[fill=green] table[x=metric,y=a4b-value,col sep=space]{foo.csv};
\end{groupplot}
\end{tikzpicture}
\end{document}