如何在每个栏中使用值标签的GNUPLOT中绘制划船堆的直方图

发布于 2025-02-12 20:26:59 字数 2165 浏览 0 评论 0原文

我想绘制划船的直方图。以下是我到目前为止所拥有的:

”在此处输入图像描述

我使用了以下代码:

reset
set bmargin 10
set lmargin 20
set rmargin 16
set tmargin 7
show margin  

set title "" font "Verdana,27"
show title
set grid

set xlabel offset 0,-5 font "Verdana,25"
set xlabel "Number of Cores"
show xlabel
set xtics font "Verdana,18"

set ylabel offset -4,0 font "Verdana,25"
set ylabel "Time (%)"
show ylabel
set yrange [0:130]
set ytics font "Verdana,18"  
set ytics (0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

set style data histogram
set style histogram rowstacked title offset 0,3
set style fill solid border lt -1
set boxwidth 0.9

set key right
set key font "Verdana,17"
set key autotitle columnheader horizontal


plot newhistogram '{/=22 1-Core}', \
        for [i=2:5] 'base_vs_FHA_speedup_1core.dat' using i:xtic(1), \
     newhistogram '{/=22 2-Cores}' lt 1, \
        for [i=2:5] 'base_vs_FHA_speedup_2core.dat' using i:xtic(1) notitle, \
     newhistogram '{/=22 4-Cores}' lt 1, \
        for [i=2:5] 'base_vs_FHA_speedup_4core.dat' using i:xtic(1) notitle, \
     newhistogram '{/=22 8-Cores}' lt 1, \
        for [i=2:5] 'base_vs_FHA_speedup_8core.dat' using i:xtic(1) notitle

我有4个不同的数据文件,带有示例数据 这种

配置Col1 col2 col3 col4 col4 col5

base_vs_fha_1core.dat

Base        5       50      40.5    4.5             
FHA         5       16      38      5       1.54x

Base        9.3     47      37.3    6.3             
FHA         9.3     15      34.3    6.3     1.54x

base_vs_vs_fha_2core.dat

Base        18      41      33.9    7.06                
FHA         16.6    13.07   30.7    7.4     1.47x

base_vs_fha_4core.dat

Base        27.7    34.3    28.3    9.6             
FHA         28.3    11.45   25.3    9.6     1.34x

喜欢 在直方图中的每个栏中都标记为相应的值和每对第二直方图顶部顶部的最后一列的值。我该如何实现?

我可以合并所有4个文件并实现相同的目标吗?

I want to draw a rowstacked histogram. The following is what I have so far:

enter image description here

I have used the code below:

reset
set bmargin 10
set lmargin 20
set rmargin 16
set tmargin 7
show margin  

set title "" font "Verdana,27"
show title
set grid

set xlabel offset 0,-5 font "Verdana,25"
set xlabel "Number of Cores"
show xlabel
set xtics font "Verdana,18"

set ylabel offset -4,0 font "Verdana,25"
set ylabel "Time (%)"
show ylabel
set yrange [0:130]
set ytics font "Verdana,18"  
set ytics (0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)

set style data histogram
set style histogram rowstacked title offset 0,3
set style fill solid border lt -1
set boxwidth 0.9

set key right
set key font "Verdana,17"
set key autotitle columnheader horizontal


plot newhistogram '{/=22 1-Core}', \
        for [i=2:5] 'base_vs_FHA_speedup_1core.dat' using i:xtic(1), \
     newhistogram '{/=22 2-Cores}' lt 1, \
        for [i=2:5] 'base_vs_FHA_speedup_2core.dat' using i:xtic(1) notitle, \
     newhistogram '{/=22 4-Cores}' lt 1, \
        for [i=2:5] 'base_vs_FHA_speedup_4core.dat' using i:xtic(1) notitle, \
     newhistogram '{/=22 8-Cores}' lt 1, \
        for [i=2:5] 'base_vs_FHA_speedup_8core.dat' using i:xtic(1) notitle

I have 4 different data files with sample data like this

Configuration col1 col2 col3 col4 col5

base_vs_FHA_1core.dat

Base        5       50      40.5    4.5             
FHA         5       16      38      5       1.54x

base_vs_FHA_2core.dat

Base        9.3     47      37.3    6.3             
FHA         9.3     15      34.3    6.3     1.54x

base_vs_FHA_4core.dat

Base        18      41      33.9    7.06                
FHA         16.6    13.07   30.7    7.4     1.47x

base_vs_FHA_8core.dat

Base        27.7    34.3    28.3    9.6             
FHA         28.3    11.45   25.3    9.6     1.34x

I want to have each bar in the histogram labeled with the corresponding value and the value of the last column on the top of the second histogram in each pair. How can I achieve this?

Can I merge all the 4 files and achieve the same goal?

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

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

发布评论

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

评论(1

拔了角的鹿 2025-02-19 20:26:59

您可以合并一个文件中的所有4个文件。我建议使用两条空行的分离,因为这样,您可以通过index轻松地解决(sub)Datablocks,请检查help Index

对于标签,您可以制作双循环,一个用于(子)数据锁,一个用于列。您必须总结列(检查help sum)才能计算标签的y位(即直方图元素的中心)。标签的X位置对于第一个数据集很特别(因为只有列列),因此可以考虑(i*3+$ 0-(i == 0)), IE i == 0如果我等于0,则返回1,否则将返回1。

您可能想在终端设置大型字体大小,而不是多次设置它,例如:设置术语pngcairo字体“,17”

在下面找到最小化的示例,作为进一步优化的起点。

脚本:

### rowstacked histogram with numbers in corresponding boxes
reset session

$Data <<EOD
# base_vs_FHA_1core.dat
col1 col2 col3 col4 col5
Base 5 50 40.5 4.5
FHA  5 16 38 5 1.54x


# base_vs_FHA_2core.dat
Base 9.3 47 37.3 6.3
FHA  9.3 15 34.3 6.3 1.54x


# base_vs_FHA_4core.dat
Base 18   41    33.9 7.06
FHA  16.6 13.07 30.7 7.4  1.47x


# base_vs_FHA_8core.dat
Base 27.7 34.3  28.3 9.6
FHA  28.3 11.45 25.3 9.6 1.34x
EOD

set xlabel "Number of Cores"
set ylabel "Time (%)"
set yrange [0:130]
set ytics 0, 10, 100
set grid

set style data histogram
set style histogram rowstacked title
set style fill solid 0.5 border lt -1
set boxwidth 0.9
set key top left noautotitle horizontal

N = 5   # number of last data column

plot newhistogram '1-Core' at 0, \
        for [i=2:N] $Data index 0 u i:xtic(1) ti columnheader, \
     newhistogram '2-Cores' lt 1 at 3, \
        for [i=2:N] '' index 1 u i:xtic(1), \
     newhistogram '4-Cores' lt 1 at 6, \
        for [i=2:N] '' index 2 u i:xtic(1), \
     newhistogram '8-Cores' lt 1 at 9, \
        for [i=2:N] '' index 3 u i:xtic(1), \
    for [i=0:3] for [j=2:N] '' index i u (i*3+$0-(i==0)): \
        ((sum [k=2:j] column(k))-column(j)*0.5):j w labels
### end of script

结果:

“在此处输入图像说明”

You can merge all 4 files in one file. I would recommend a separation with two empty lines, because with this, you can easily address the (sub)datablocks via index, check help index.

For the labels you can make a double loop, one for the (sub)datablocks and one for the columns. You have to sum up the columns (check help sum) to calculate the y-position of the label (i.e. center of the histogram element). The x-position of the labels is special for the first dataset (since only this has a columnheader), this is taken into account with (i*3+$0-(i==0)), i.e. i==0 will return 1 if i equals 0, and 0 otherwise.

Instead of setting a large fontsize many times you might want to set it in the terminal, e.g. something like: set term pngcairo font ",17".

Find below a minimized example as a starting point for further optimization.

Script:

### rowstacked histogram with numbers in corresponding boxes
reset session

$Data <<EOD
# base_vs_FHA_1core.dat
col1 col2 col3 col4 col5
Base 5 50 40.5 4.5
FHA  5 16 38 5 1.54x


# base_vs_FHA_2core.dat
Base 9.3 47 37.3 6.3
FHA  9.3 15 34.3 6.3 1.54x


# base_vs_FHA_4core.dat
Base 18   41    33.9 7.06
FHA  16.6 13.07 30.7 7.4  1.47x


# base_vs_FHA_8core.dat
Base 27.7 34.3  28.3 9.6
FHA  28.3 11.45 25.3 9.6 1.34x
EOD

set xlabel "Number of Cores"
set ylabel "Time (%)"
set yrange [0:130]
set ytics 0, 10, 100
set grid

set style data histogram
set style histogram rowstacked title
set style fill solid 0.5 border lt -1
set boxwidth 0.9
set key top left noautotitle horizontal

N = 5   # number of last data column

plot newhistogram '1-Core' at 0, \
        for [i=2:N] $Data index 0 u i:xtic(1) ti columnheader, \
     newhistogram '2-Cores' lt 1 at 3, \
        for [i=2:N] '' index 1 u i:xtic(1), \
     newhistogram '4-Cores' lt 1 at 6, \
        for [i=2:N] '' index 2 u i:xtic(1), \
     newhistogram '8-Cores' lt 1 at 9, \
        for [i=2:N] '' index 3 u i:xtic(1), \
    for [i=0:3] for [j=2:N] '' index i u (i*3+$0-(i==0)): \
        ((sum [k=2:j] column(k))-column(j)*0.5):j w labels
### end of script

Result:

enter image description here

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