我有一个条形图,我想强调两对和两对属于一起。所以我需要在 Cornell Box 和 Conference Room 以及 Conference Room 和 Sponza 之间添加一些填充。此外,也许在图表之间画一条线可以帮助划分它们?
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
\begin{center}
\begin{tikzpicture}
\pgfplotstableread{
1.00 1.9946 2.8193
1.00 1.9947 2.9286
1.00 1.9837 2.8977
1 1.9857 2.9523
1 1.9706 2.8329
1 1.9854 2.9093
}\datatable
\node [align=center,
text width=3cm, inner sep=0.25cm] at (1.90cm, -0.40cm) {\textsc{Cornell Box}};
\node [align=center,
text width=4cm, inner sep=0.25cm] at (5.65cm, -0.40cm) {\textsc{Conference Room}};
\node [align=center,
text width=4cm, inner sep=0.25cm] at (9.6cm, -0.40cm) {\textsc{Sponza}};
\begin{axis}[
ybar,
title style={align=center},
title={Speedup using three GPUs on a single system\\after $200$ and $1000$ iterations },
ticks=both,
ytick={0, 1.00, 2.00, 3.00},
axis x line = bottom,
axis y line = left,
axis line style={-|},
nodes near coords = \rotatebox{90}{{\pgfmathprintnumber[fixed zerofill, precision=3]{\pgfplotspointmeta}}},
nodes near coords align={vertical},
every node near coord/.append style={font=\small, fill=white, yshift=0.5mm},
enlarge y limits={lower, value=0.1},
enlarge y limits={upper, value=0.22},
ylabel=Speedup,
xtick=data,
ymin = 0,
ymajorgrids,
xticklabels={
$200$,
$1000$,
$200$,
$1000$,
$200$,
$1000$},
legend style={at={(0.5, -0.30)}, anchor=north, legend columns=3},
every axis legend/.append style={nodes={right}, inner sep = 0.2cm},
x tick label style={align=center, yshift=-0.6cm},
enlarge x limits=0.1,
width=13cm,
height=7cm,
]
\pgfplotsinvokeforeach {0,...,2}{
\addplot table [x expr=\coordindex, y index=#1] {\datatable};
}
\legend{1 GPU\hspace*{8pt}, 2 GPUs\hspace*{8pt}, 3 GPUs}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
答案1
您可以使用以下方法将每个系列的每隔一个条形图稍微向左移动
x expr={\coordindex-mod(\coordindex,2)/4}
我可能会手动绘制垂直线,使用类似下面的方法(参见如何在绘图中添加零线?了解添加横跨整个绘图区域的线的方法)
\draw (axis cs:1.375,0) -- ({axis cs:1.375,0}|-{rel axis cs:0.5,1});
\draw (axis cs:3.375,0) -- ({axis cs:3.375,0}|-{rel axis cs:0.5,1});
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\begin{document}
\begin{center}
\begin{tikzpicture}
\pgfplotstableread{
1.00 1.9946 2.8193
1.00 1.9947 2.9286
1.00 1.9837 2.8977
1 1.9857 2.9523
1 1.9706 2.8329
1 1.9854 2.9093
}\datatable
\node [align=center,
text width=3cm, inner sep=0.25cm] at (1.90cm, -0.40cm) {\textsc{Cornell Box}};
\node [align=center,
text width=4cm, inner sep=0.25cm] at (5.65cm, -0.40cm) {\textsc{Conference Room}};
\node [align=center,
text width=4cm, inner sep=0.25cm] at (9.6cm, -0.40cm) {\textsc{Sponza}};
\begin{axis}[
ybar,
title style={align=center},
title={Speedup using three GPUs on a single system\\after $200$ and $1000$ iterations },
ticks=both,
ytick={0, 1.00, 2.00, 3.00},
axis x line = bottom,
axis y line = left,
axis line style={-|},
nodes near coords = \rotatebox{90}{{\pgfmathprintnumber[fixed zerofill, precision=3]{\pgfplotspointmeta}}},
nodes near coords align={vertical},
every node near coord/.append style={font=\small, fill=white, yshift=0.5mm},
enlarge y limits={lower, value=0.1},
enlarge y limits={upper, value=0.22},
ylabel=Speedup,
xtick=data,
ymin = 0,
ymajorgrids,
xticklabels={
$200$,
$1000$,
$200$,
$1000$,
$200$,
$1000$},
legend style={at={(0.5, -0.30)}, anchor=north, legend columns=3},
every axis legend/.append style={nodes={right}, inner sep = 0.2cm},
x tick label style={align=center, yshift=-0.6cm},
enlarge x limits=0.1,
width=13cm,
height=7cm,
]
\pgfplotsinvokeforeach {0,...,2}{
\addplot table [x expr={\coordindex-mod(\coordindex,2)/4}, y index=#1] {\datatable};
}
\draw (axis cs:1.375,0) -- ({axis cs:1.375,0}|-{rel axis cs:0.5,1});
\draw (axis cs:3.375,0) -- ({axis cs:3.375,0}|-{rel axis cs:0.5,1});
\legend{1 GPU\hspace*{8pt}, 2 GPUs\hspace*{8pt}, 3 GPUs}
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}