gnuplot:如何用聚集的堆叠直方图将总和放在钢筋上方

发布于 2025-01-30 03:04:08 字数 1984 浏览 3 评论 0原文

多亏了这个问题 gnuplot rowStacked直方图:如何将总和放在bars上 及其答案,我学会了如何添加在其条形上方堆叠直方图。但是,我不知道如何使用聚集的堆叠直方图实现此目标。如下代码所示,我可以获得似乎放置在正确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:($2+$3+$4+$5+$6+$7):(sprintf('%d', $2+$3+$4+$5+$6+$7)) 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:($2+$3+$4+$5+$6+$7):(sprintf('%d', $2+$3+$4+$5+$6+$7)) 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:($2+$3+$4+$5+$6+$7):(sprintf('%d', $2+$3+$4+$5+$6+$7)) not with labels offset 0,0.7

数据文件:

  • a.csv

     设备,下载,传输,返回,处理,等待,开销
    查找X2 Pro,350,0,0,287,1,24
    OnePlus 8,350,29,19,410,30,138
     
  • b.csv

     设备,下载,传输,返回,处理,等待,开销
    查找X2 Pro,350,0,0,293,1,26
    像素6,350,81,21,216,100,228
     
  • c.csv

     设备,下载,传输,返回,处理,等待,开销
    像素6,350,0,0,436,2,43
    像素3,350,140,​​46,187,52,206
     

“

Thanks to the question gnuplot rowstacked histogram: how to put sum above bars and its answer, I learned how to add the sum of stacked histograms above their bars. However, I can't figure out how to achieve this with stacked histograms that are clustered. As shown in the below code, I can get the sum which seem to be placed at the right y coordinates.

Unfortunately, I don't know how to change the x coordinates for the second and third clusters, so they end up overlapping the first cluster's sum labels. What do I need to do to change the x coordinates of the sums so that they appear over the correct bars?


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:($2+$3+$4+$5+$6+$7):(sprintf('%d', $2+$3+$4+$5+$6+$7)) 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:($2+$3+$4+$5+$6+$7):(sprintf('%d', $2+$3+$4+$5+$6+$7)) 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:($2+$3+$4+$5+$6+$7):(sprintf('%d', $2+$3+$4+$5+$6+$7)) not with labels offset 0,0.7

Data files:

  • a.csv

    Device,Download,Transfer,Return,Processing,Wait,Overhead
    Find X2 Pro,350,0,0,287,1,24
    OnePlus 8,350,29,19,410,30,138
    
  • b.csv

    Device,Download,Transfer,Return,Processing,Wait,Overhead
    Find X2 Pro,350,0,0,293,1,26
    Pixel 6,350,81,21,216,100,228
    
  • c.csv

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

gnplot output

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

守望孤独 2025-02-06 03:04:08

在这里,我试图清理并简化您的脚本。我将数据包含在Datablocks中,因此仅复制&糊&跑步。
检查帮助sum帮助Columnheader ...我希望其余的是自我解释。

脚本:

### 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 ($0+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 ($0+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 ($0+7):(total=mySum(0)):(sprintf('%d', total)) w labels offset 0,0.7, \
### end of script

结果:

”在此处输入图像描述”

Here I tried to clean up and simplify your script. I included the data as datablocks, so it is simply copy & paste & run.
Check help sum, help columnheader... I hope the rest is self-explaining.

Script:

### 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 ($0+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 ($0+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 ($0+7):(total=mySum(0)):(sprintf('%d', total)) w labels offset 0,0.7, \
### end of script

Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文