我想复制一个像this one这样的条形图,即:多个组,每个组有许多条(在我的例子中是4条),每个条被分割成几个切片(在我的例子中是两个切片)。
在我的例子中,我有四种算法应用于不同大小的向量(2^0到2^20)。每个算法都有两个“部分”,即本地计算和通信。对于每个向量大小,我希望显示每个算法执行本地计算和通信所需的时间,以及与这两个部分的总和相对应的总时间。
因此,我希望每个向量大小都有一个组。在每一组中,有对应于四个算法的四个条,并且每个条被分割成(例如)红色部分对应于本地计算,蓝色部分对应于通信。
这在gnuplot中可行吗?我可以提供任何有用格式的数据。
在此之前,非常感谢您。
发布于 2014-02-03 18:32:02
对于您的数据集,堆叠本地和通信部分是没有意义的,因为通信部分太小了,无法在图中看到它。在任何情况下,根据进一步的需求(图例条目、刻度标签等),将堆叠和集群结合起来也是相当棘手的。
下面是一个如何为您的数据集绘制聚类直方图的示例:
set style histogram clustered gap 1
set style data histogram
set style fill solid 1.0 noborder
set termoption enhanced
set xtics out nomirror
myxtic(x) = sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5)))
plot 'test.dat' using ($2+$3):xtic(myxtic(stringcolumn(1))) title 'Algorithm 1',\
for [i=2:4] '' using (column(2*i)+column(2*i+1)) title sprintf('Algorithm %d', i)结果是:

要按算法分组,可以使用newhistogram关键字创建新组:
set style histogram rowstacked title offset 4,1
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set xtics rotate by 90 right
plot newhistogram "Algorithm 1" lt 1,\
'test.dat' using 2:xtic(1) title columnheader, \
'' using 3 title columnheader,\
newhistogram "Algorithm 2" lt 1,\
'test.dat' using 4:xtic(1) notitle, \
'' using 5 notitle,\
newhistogram "Algorithm 3" lt 1,\
'test.dat' using 6:xtic(1) notitle, \
'' using 7 notitle,\
newhistogram "Algorithm 4" lt 1,\
'test.dat' using 8:xtic(1) notitle, \
'' using 9 notitlelocal和comm dat是堆叠在一起的,但comm部分太小,以至于您在图形中看不到它(仅当您放大时)。
对于输出,我使用了4.6.3和以下设置:
set terminal pngcairo size 1000,400
set output 'test.png'
set xtics font ',6'结果是:

更复杂的xtics显示需要一些技巧,因为对于直方图,xtics不被视为数字,而是字符串。下面是一个示例:
set terminal pngcairo size 1000,400
set output 'test.png'
set style histogram rowstacked title offset 0,-0.5
set bmargin 3
set boxwidth 0.9 relative
set style fill solid 1.0 border lt -1
set termoption enhanced
set xtics out nomirror
myxtic(x) = (int(floor(log(x)/log(2) + 0.5)) % 5 == 0) ? sprintf('2^{%d}', int(floor(log(x)/log(2) + 0.5))) : ""
plot newhistogram "Algorithm 1" lt 1,\
'test.dat' using 2:xtic(myxtic(real(stringcolumn(1)))) title columnheader, \
'' using 3 title columnheader,\
newhistogram "Algorithm 2" lt 1,\
'test.dat' using 4:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 5 notitle,\
newhistogram "Algorithm 3" lt 1,\
'test.dat' using 6:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 7 notitle,\
newhistogram "Algorithm 4" lt 1,\
'test.dat' using 8:xtic(myxtic(real(stringcolumn(1)))) notitle, \
'' using 9 notitle其结果是

https://stackoverflow.com/questions/21517922
复制相似问题