1

我用 gnuplot 堆叠了条形图。目前我只获取数据文件并手动设置数据标题。由于我根据数据量对数据库进行排序,因此重新输入和查看订单需要花费时间。

这是我的 Gnuplot 文件:

set term pos eps font 20
set style data histogram
set style histogram rowstacked
set style fill solid border -1
set key invert reverse right outside 
set boxwidth 0.75
set format y "%.0f%%"
set style line 2 lc rgb "#EDEBE4" lt 1 lw 2
set style line 3 lc rgb "#A7ABA6" lt 1 lw 2
set title "Classification"

set ylabel "Percentage"
set xlabel "System"
set yrange [0:100]
set output 'output.eps'
plot 'datafile' \
    using($2):xtic(1)   t "stack-1" lt -1 fs pattern 3 , \
''  using($3)           t "stack-2" lt -1 fs pattern 2, \
''  using($4)           t "stack-3" lt -1 fs pattern 5, \
''  using($5)           t "stack-4" lt -1 fs pattern 9, \
''  using($6)           t "stack-5" ls 3, \
''  using($7)           t "stack-6" lt -1 fs pattern 6, \
''  using($8)           t "stack-7" lt -1 fs pattern 4, \
''  using($9)           t "stack-8" ls 2   

这是我当前的数据文件:

CS  35.08   33.12   22.49   3.72    2.73    1.03    1.76    0.08
FL  58.22   9.36    21.46   4.34    3.65    2.97    0.00    0.00
HB  40.27   19.29   18.52   14.37   6.13    0.91    0.29    0.21
HD  30.32   22.51   31.63   1.10    9.51    2.53    1.50    0.90
MR  34.65   24.37   15.59   7.46    15.42   1.56    0.66    0.29
ZK  29.65   18.54   30.63   6.91    9.46    1.28    2.85    0.68
All 36.74   23.88   22.01   7.40    7.18    1.42    1.06    0.31

我必须将我的数据文件更改为这样:

    stacked-1   stack-2 stack-3 stack-4 stack-5 stack-6 stack-7 stack-8
CS  35.08   33.12   22.49   3.72    2.73    1.03    1.76    0.08
FL  58.22   9.36    21.46   4.34    3.65    2.97    0.00    0.00
HB  40.27   19.29   18.52   14.37   6.13    0.91    0.29    0.21
HD  30.32   22.51   31.63   1.10    9.51    2.53    1.50    0.90
MR  34.65   24.37   15.59   7.46    15.42   1.56    0.66    0.29
ZK  29.65   18.54   30.63   6.91    9.46    1.28    2.85    0.68
All 36.74   23.88   22.01   7.40    7.18    1.42    1.06    0.31

输出:

在此处输入图像描述

如何从我的数据文件的第一行自动创建条形图标题/图例?另外我的脚本仍然需要手动使用模式样式。谢谢!

4

1 回答 1

1

title columnhead(2)您可以选择某个列的标题作为关键条目。所以你的plot命令变成

plot 'datafile' \
    using 2:xtic(1) title columnhead(1) lt -1 fs pattern 3 , \
''  using 3         title columnhead(2) lt -1 fs pattern 2, \
''  using 4         title columnhead(3) lt -1 fs pattern 5, \
''  using 5         title columnhead(4) lt -1 fs pattern 9, \
''  using 6         title columnhead(5) ls 3, \
''  using 7         title columnhead(6) lt -1 fs pattern 6, \
''  using 8         title columnhead(7) lt -1 fs pattern 4, \
''  using 9         title columnhead(8) ls 2   

这非常冗长,因为您的第一列没有标题,因此从中选择标题的列与用于值的列相差一个。

如果您要为第一列插入一个虚拟标题,那么使用set key autotitle columnheader.

更改datafile

desc stacked-1   stack-2 stack-3 stack-4 stack-5 stack-6 stack-7 stack-8
CS  35.08   33.12   22.49   3.72    2.73    1.03    1.76    0.08
FL  58.22   9.36    21.46   4.34    3.65    2.97    0.00    0.00
HB  40.27   19.29   18.52   14.37   6.13    0.91    0.29    0.21
HD  30.32   22.51   31.63   1.10    9.51    2.53    1.50    0.90
MR  34.65   24.37   15.59   7.46    15.42   1.56    0.66    0.29
ZK  29.65   18.54   30.63   6.91    9.46    1.28    2.85    0.68
All 36.74   23.88   22.01   7.40    7.18    1.42    1.06    0.31

然后使用

set key invert reverse right outside autotitle columnheader
plot 'datafile' \
    using 2:xtic(1) lt -1 fs pattern 3 , \
''  using 3         lt -1 fs pattern 2, \
''  using 4         lt -1 fs pattern 5, \
''  using 5         lt -1 fs pattern 9, \
''  using 6         ls 3, \
''  using 7         lt -1 fs pattern 6, \
''  using 8         lt -1 fs pattern 4, \
''  using 9         ls 2   
于 2014-06-30T08:06:44.200 回答