gpt4 book ai didi

gnuplot - 使用 Gnuplot 堆叠和分组的直方图

转载 作者:行者123 更新时间:2023-12-05 07:59:33 27 4
gpt4 key购买 nike

我想重现像 this one 这样的条形图,即:多个组,每个组都有很多条(在我的例子中是 4 个条),每个条被分割成几个切片(在我的例子中是两个切片)。

在我的例子中,我有四种算法应用于不同大小的向量(2^0 到 2^20)。每个算法都有两个“部分”,本地计算和通信。对于每个向量大小,我想显示每个算法执行本地计算和通信所需的时间,以及对应于这两个部分总和的总时间。

因此,我希望每个向量大小都有一个组。在每组中,有四个条对应于四种算法,每个条被分割成(例如)红色部分对应本地计算,蓝色部分对应通信。

这对 gnuplot 可行吗?我可以提供有用的任何格式的数据。

非常感谢。

最佳答案

对于您的数据集,堆叠本地和通信部分没有意义,因为通信部分太小以至于无法在图中看到。在任何情况下,根据进一步的要求(图例条目、刻度标签等),将堆叠式和集群式组合起来也非常棘手。

以下是如何为您的数据集绘制聚类直方图的示例:

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)

结果是:

enter image description here

要按算法分组,您可以使用 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 notitle

localcomm 数据是堆叠在一起的,但是 comm 部分太小了,你在图中看不到它(只有当你放大时)。

对于输出,我使用了 4.6.3 和以下设置:

set terminal pngcairo size 1000,400
set output 'test.png'
set xtics font ',6'

结果是:

enter image description here

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

结果

enter image description here

关于gnuplot - 使用 Gnuplot 堆叠和分组的直方图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com