我想制作一个具有 xbar 堆叠样式的图,但一些 ylabel 应该组合在一起。
我找到了这个问题和解决方案我如何将“ybar”和“ybar stacked”与 pgfplots 混合?,但对我来说并不容易理解。另外,它是用于 ybars 的,而我必须使用 xbars。还有多个级别的组,但我只需要使用一个级别进行分组。
\documentclass{standalone}
\usepackage{pgfplots, pgfplotstable}
\begin{document}
\pgfplotstableread[col sep=space, header=false]{
5-16-64KiB-128KiB 0.555776 0.196256 0.005536 0.098208 0.133056
5-16-1MiB-2MiB 0.52304 0.126112 0.005472 0.064448 0.08448
5-32-64KiB-128KiB 0.36992 0.377856 0.005504 0.090304 0.110208
5-32-1MiB-2MiB 0.336352 0.252224 0.005568 0.06496 0.092384
10-16-64KiB-128KiB 0.399488 0.377952 0.005568 0.109184 0.140096
10-16-1MiB-2MiB 0.366976 0.252128 0.005472 0.07088 0.084832
10-32-64KiB-128KiB 0.397312 0.629408 0.005568 0.096768 0.125408
10-32-1MiB-2MiB 0.349664 0.37792 0.005632 0.070784 0.079872
15-16-64KiB-128KiB 0.477472 0.573536 0.005504 0.092192 0.120992
15-16-1MiB-2MiB 0.436576 0.377728 0.005504 0.065248 0.088416
15-32-64KiB-128KiB 0.46848 0.769408 0.005504 0.155744 0.190272
15-32-1MiB-2MiB 0.342144 0.755168 0.005472 0.0728 0.092768
}\datatable
\begin{tikzpicture}
\begin{axis}[
width=\textwidth, %
xbar stacked, %
y=-0.5cm,%
bar width=0.3cm,%
yticklabels from table={\datatable}{0},%
enlarge y limits={abs=0.45cm},%
ytick=data,%
xlabel={Ausführungszeit in ms}, %
ylabel={Parameter}, %
xmin=0.0, xmax=2.0, %
legend pos=south east, %
]%
\addplot table [x=1, y expr=\coordindex] {\datatable};
\addplot table [x=2, y expr=\coordindex] {\datatable};
\addplot table [x=3, y expr=\coordindex] {\datatable};
\addplot table [x=4, y expr=\coordindex] {\datatable};
\addplot table [x=5, y expr=\coordindex] {\datatable};
\legend{%
}
\end{axis}
\end{tikzpicture}
\end{document}
该图像是上述最小示例的结果:
我想要这样的东西:
如果用这种方式显示信息太复杂或者不好:还有其他方法可以让我以情节的形式呈现这些信息吗?
编辑:好的,我尝试将上面链接中的代码转换为分组 xbar:
\newcounter{groupcount}
\pgfplotsset{
draw group line/.style n args={5}{
after end axis/.append code={
\setcounter{groupcount}{0}
\pgfplotstableforeachcolumnelement{#1}\of\datatable\as\cell{%
\def\temp{#2}
\ifx\temp\cell
\ifnum\thegroupcount=0
\stepcounter{groupcount}
\pgfplotstablegetelem{\pgfplotstablerow}{[index]0}\of\datatable
\coordinate [xshift=#4] (startgroup) at (axis cs:0,\pgfplotsretval);
\else
\pgfplotstablegetelem{\pgfplotstablerow}{[index]0}\of\datatable
\coordinate [xshift=#4] (endgroup) at (axis cs:0,\pgfplotsretval);
\fi
\else
\ifnum\thegroupcount=1
\setcounter{groupcount}{0}
\draw [
shorten >=-#5,
shorten <=-#5
] (startgroup) -- node [anchor=east] {#3} (endgroup);
\fi
\fi
}
\ifnum\thegroupcount=1
\setcounter{groupcount}{0}
\draw [
shorten >=-#5,
shorten <=-#5
] (startgroup) -- node [anchor=east] {#3} (endgroup);
\fi
}
}
}
\pgfplotstableread[col sep=semicolon, header=false]{
X;C;M;K1;K2;K3;M1;M2
1;1;1;0.555776;0.196256;0.005536;0.098208;0.133056
2;1;2;0.52304;0.126112;0.005472;0.064448;0.08448
4;2;1;0.36992;0.377856;0.005504;0.090304;0.110208
5;2;2;0.336352;0.252224;0.005568;0.06496;0.092384
7;3;1;0.399488;0.377952;0.005568;0.109184;0.140096
8;3;2;0.366976;0.252128;0.005472;0.07088;0.084832
10;4;1;0.397312;0.629408;0.005568;0.096768;0.125408
11;4;2;0.349664;0.37792;0.005632;0.070784;0.079872
13;5;1;0.477472;0.573536;0.005504;0.092192;0.120992
14;5;2;0.436576;0.377728;0.005504;0.065248;0.088416
16;6;1;0.46848;0.769408;0.005504;0.155744;0.190272
17;6;2;0.342144;0.755168;0.005472;0.0728;0.092768
}
\begin{tikzpicture}
\begin{axis}[
xlabel={Ausführungszeiten in ms}, %
ylabel={Parameter}, %
width=\textwidth, %
y=-0.4cm,%
bar width=0.3cm,%
enlarge y limits={abs=0.45cm},%
legend pos=north east, %
area legend, %
ytick=data, %
ylabel near ticks, %
yticklabels from table={\datatable}{M},
xmin=0.0,xmax=2.0, %
xtick={0.0,0.2,...,2.0}, %
xbar stacked, %
bar width=10pt, %
area legend, %
draw group line={C}{1}{5/16}{-80pt}{8pt},
draw group line={C}{2}{5/32}{-80pt}{8pt},
draw group line={C}{3}{10/16}{-80pt}{8pt},
draw group line={C}{4}{10/32}{-80pt}{8pt},
draw group line={C}{5}{15/16}{-80pt}{8pt},
draw group line={C}{6}{16/32}{-80pt}{8pt},
]\datatable
\addplot table[x=K1,y=X] \datatable;\addlegendentry{1}
\addplot table[x=K2,y=X] \datatable;\addlegendentry{2}
\addplot table[x=K3,y=X] \datatable;\addlegendentry{3}
\addplot table[x=M1,y=X] \datatable;\addlegendentry{4}
\addplot table[x=M2,y=X] \datatable;\addlegendentry{5}
\end{axis}
\end{tikzpicture}
如果有人有什么建议,我会接受一切:)!