首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将标题自动放在gnuplot上-堆叠

将标题自动放在gnuplot上-堆叠
EN

Stack Overflow用户
提问于 2014-06-30 03:30:55
回答 1查看 699关注 0票数 1

我已经把条形图和侏儒图堆在一起了。目前,我只获取数据文件,并手动设置数据标题。由于我要根据数据量对数据库进行排序,因此重新键入和查看订单需要花费时间。

这是我的Gnuplot文件:

代码语言:javascript
复制
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   

这是我当前的数据文件:

代码语言:javascript
复制
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

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

代码语言:javascript
复制
    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

产出:

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-30 08:06:44

使用title columnhead(2),您可以选择某个列的标题作为键项。所以您的plot命令变成

代码语言:javascript
复制
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更改为

代码语言:javascript
复制
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

然后使用

代码语言:javascript
复制
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   
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24482597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档