gnuplot:如何使用聚类堆叠直方图将总和放在条形图上方

gnuplot: How to put sum above bars with clustered stacked histograms

感谢问题 及其答案,我学会了如何将堆叠直方图的总和添加到柱上方。但是,我无法弄清楚如何使用聚集的堆叠直方图来实现这一点。如下面的代码所示,我可以得到似乎放在正确 y 坐标上的总和。

不幸的是,我不知道如何更改第二个和第三个集群的 x 坐标,所以它们最终与第一个集群的总和标签重叠。我需要做什么来更改总和的 x 坐标,以便它们出现在正确的柱上?


set term png size 1200, 500
set output "graph.png"
set datafile separator ","

set boxwidth 0.5
set style fill solid
set style data histograms
set style histogram rowstack

set offset -1.3,-0.3,100,0
set yrange [*:*] noextend
set xrange [*:*] noextend

set key outside
set key right top
set ylabel "Time (ms)"
set xtics font ", 10"

plot newhistogram at 0, "a.csv" u 2:xtic(1) t "Download" lc 1, \
    '' u 3:xtic(1) t "Transfer" lc 2, \
    '' u 4:xtic(1) t "Return" lc 3, \
    '' u 5:xtic(1) t "Processing" lc 4, \
    '' u 6:xtic(1) t "Wait" lc 5, \
    '' u 7:xtic(1) t "Overhead" lc 6, \
    '' u 0:(+++++):(sprintf('%d', +++++)) not with labels offset 0,0.7, \
  newhistogram at 3, "b.csv" u 2:xtic(1) t "" lc 1,\
    for [i=3:7] '' u i:xtic(1) t "" lc (i - 1), \
    '' u 0:(+++++):(sprintf('%d', +++++)) not with labels offset 0,0.7, \
  newhistogram at 6, "c.csv" u 2:xtic(1) t "" lc 1,\
    for [i=3:7] '' u i:xtic(1) t "" lc (i - 1), \
    '' u 0:(+++++):(sprintf('%d', +++++)) not with labels offset 0,0.7

数据文件:

我在这里尝试清理和简化您的脚本。我将数据作为数据块包含在内,因此只需复制和粘贴 & 运行。 检查help sumhelp columnheader...我希望剩下的是self-explaining。

脚本:

### rowstacked histogram with total above bars
reset session

$DataA <<EOD
Device,Download,Transfer,Return,Processing,Wait,Overhead
Find X2 Pro,350,0,0,287,1,24
OnePlus 8,350,29,19,410,30,138
EOD

$DataB <<EOD
Device,Download,Transfer,Return,Processing,Wait,Overhead
Find X2 Pro,350,0,0,293,1,26
Pixel 6,350,81,21,216,100,228
EOD

$DataC <<EOD
Device,Download,Transfer,Return,Processing,Wait,Overhead
Pixel 6,350,0,0,436,2,43
Pixel 3,350,140,46,187,52,206
EOD

set datafile separator ","
set boxwidth 0.5
set style fill solid
set style data histograms
set style histogram rowstack

set offset -1.3,-0.3,100,0
set xrange [0:]
set xtics font ", 10" right rotate by 45
set yrange [0:*]
set ylabel "Time (ms)"
set key outside right top noautotitle

mySum(n) = sum [_i=2:7] column(_i)

plot newhistogram at 2, \
         for [i=2:7] $DataA u i:xtic(1) ti columnheader(i) lc i-1, \
         '' u ([=10=]+1):(total=mySum(0)):(sprintf('%d', total)) w labels offset 0,0.7, \
     newhistogram at 4,\
         for [i=2:7] $DataB u i:xtic(1) lc i-1, \
         '' u ([=10=]+4):(total=mySum(0)):(sprintf('%d', total)) w labels offset 0,0.7, \
     newhistogram at 7, \
         for [i=2:7] $DataC u i:xtic(1) lc i-1, \
         '' u ([=10=]+7):(total=mySum(0)):(sprintf('%d', total)) w labels offset 0,0.7, \
### end of script

结果: