gnuplot:如何在群集直方图的条形图上绘制点?

时间:2019-08-06 19:26:29

标签: gnuplot histogram

我正在使用histogram clustered制作一些加速图。对于每个实例,我将使用2、4、8、16和32台计算机达到的加速速度分组。我还用一条线表示“线性加速”。但是,对于每个实例/计算机,我还要在其上方放置一个point,以表示要与之比较的值。

我尝试使用相同的策略来绘制框,但是使用点代替。但是,这些点绘制在同一位置,它们没有遵循“聚集”间距。

这是我正在使用的代码:


set yrange [0:105]
set grid ytics

set style line 1 lc rgb '#0e1111' lt 1 lw 2 pt -1 ps 1.0 
set xlabel "Instance" font "sans, 18"
set ylabel "Normalized Speedup (In %)" font "sans, 18"

set style histogram clustered

plot  for [COL=2:2] 'data.dat' using COL:xticlabels(1) title columnheade lc rgbcolor "black" lt -1 fs pattern 3,\
for [COL=3:3] 'data.dat' using COL:xticlabels(1) title columnheade lc rgbcolor "black" lt -1 fs pattern 1,\
"linear.t" t "Lin" with linespoints ls 1

数据示例

0   2   4   8   16  32
ta22    65.67   37.98   38.16   30.91   19.24 
ta23    73.69   45.59   48.59   44.20   34.19 

这就是我得到的。这些就是我想要的。

https://imgur.com/a/ugFhQdf

有可能发生这种事吗?它也会像错误栏一样工作。但是,没有一行,只有一个“最大值”。

谢谢大家!

1 个答案:

答案 0 :(得分:1)

我无法运行您的代码。但是,根据您的图像,我了解您的问题。 为了绘制所需的点,我创建了一个名为points.dat的文件。

0   2   4   8   16  32
ta22    75.67   47.98   48.16   40.91   29.24 
ta23    83.69   55.59   58.59   54.20   44.19

这没什么是your data + 10
gnuplot代码

reset                                           # Restore the default settings
set encoding utf8                               # Selects the character encoding
set terminal pngcairo size 800,500              # Generates output in png
set output 'histogram.png'                      # The filename
set grid ytics ls -1 lc 'gray'                  # Grid lines ytics only
set yrange [0:100]                              # Yrange 0 to 100 (% ?)
set style data histograms                       # Type of data: histograms
set style histogram clustered gap 1             # Type of histogram: clustered with gap 1
set style fill transparent solid 1 border lt -1 # Style: fillstyle and border

stats 'points.dat' skip 1 matrix nooutput       # Statistical summary with skip
                                                # for header and without output 

numRows = STATS_size_y              # Y size of matrix (rows)
numCols = STATS_size_x              # X size of matrix (columns)

array Value[numRows*(numCols-1)]    # Create an array based on size of data

position = 0                        # Count to position on array

# Loop for populate the array
do for [i=1:numRows]{
    do for [j=2:numCols]{
        # Statistical summary (with skip for header) at each value and without output 
        stats 'points.dat' skip 1 u j every ::i-1::i-1 nooutput
        position = position + 1         # Increase the count of position
        Value[position] = STATS_min     # Define the array-value as result of statistical analysis
    }
}

# Mapping functions: 
# i-cluster/rows (x-values),
# j-column (y-values)
# ignore the cluster name ($1)
posX(i, j) = (i - 1) + 1.0*(j - numCols + 3)/numCols        # To X-values
posY(i, j) = i == 1 ? Value[j] : Value[numCols - 1 + j]     # To Y-values

# The plot itself as newhistogram and nested loops:
# i-loop to bars and title as columnheade
# j-loop to rows (x-values)
# k-loop to columns (y-values)
plot \
    newhistogram ,\
        for [i=2:numCols]\
            'data.dat' u i:xticlabels(1) ls i-1 title columnheade,\
        for [j=1:numRows] \
            for [k=1:numCols-1] \
                '+' u (posX(j, k)):(posY(j, k)) w p pt 5 ps 0.75 lc 'black' notitle 

产生

histogram