在堆叠的条形图中用文字设置图例/图案之间的空间 [英] setting space between legend/pattern with the text in stacked bar-chart

查看:229
本文介绍了在堆叠的条形图中用文字设置图例/图案之间的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有gnuplot数据文件:

CS  31.73   18.32   20.78   22.88   1.97    1.29    0.90    2.01
FL  43.27   29.45   15.64   6.55    1.64    1.27    2.18    0.00
HB  32.44   20.43   14.89   14.53   5.42    10.92   0.80    0.31
HD  28.53   7.27    29.53   20.33   9.18    0.93    2.04    1.44
MR  22.56   36.19   10.66   15.51   9.45    4.32    0.80    0.31
ZK  27.15   10.81   27.40   16.10   8.05    7.24    1.06    1.71
All 30.00   21.35   18.05   16.82   6.14    5.39    1.11    0.85

还有我的gnuplot脚本:

set term pos eps font 20
set style data histogram
set style histogram rowstacked
set key invert reverse above
set boxwidth 0.8
set format y "%.0f%%"
set border 3 
set yrange [0:100]
set size 0.9 , 1.8

set label 1 "1092" at -0.3,103 font "Times-Roman, 17" 
set label 2 "500" at 0.7,103 font "Times-Roman, 17" 
set label 3 "1000" at 1.8,103 font "Times-Roman, 17" 
set label 4 "500" at 2.8,103  font "Times-Roman, 17" 
set label 5 "1000" at 3.8,103 font "Times-Roman, 17" 
set label 6 "500" at 4.8,103 font "Times-Roman, 17" 
set label 7 "500" at 5.8,103 font "Times-Roman, 17" 


set output 'aspect.eps'
plot 'a3b-aspect' \
    using($2):xtic(1)   t "pattern 1"  lc rgb "#006600"  lt -1 fs pattern 1, \
''  using($3)           t "pattern 2"  lc rgb "#006600"  lt -1 fs pattern 2, \
''  using($4)           t "pattern 3"  lc rgb "#330000"  lt -1 fs pattern 3, \
''  using($5)           t "pattern 4" lc rgb "#000099"  lt -1 fs pattern 4, \
''  using($6)           t "pattern 5"  lc rgb "#000099"  lt -1 fs pattern 5, \
''  using($7)           t "pattern 6"   lc rgb "#000099"  lt -1 fs pattern 6, \
''  using($8)           t "pattern 7"  lc rgb "#000099"  lt -1 fs pattern 7, \
''  using($5)           t "pattern 3" lc rgb "#660000"  lt -1 fs pattern 3, \
''  using($6)           t "pattern 3"   lc rgb "#990000"  lt -1 fs pattern 3

输出:

我必须删除图例(上面的图案)和文本之间的空间.我们可以自定义矩形大小吗?并颠倒我的图例顺序...条形图中的底部图案应该是第一个图例. 谢谢

解决方案

图例键的默认对齐方式为Right,这与使用reverse一样不适合:设置Left选项. /p>

(可选)您还可以使用width选项增加或减少为文本保留的空间.

要在第一行中显示第一行,请不要使用invert选项.

使用键设置

set key reverse above Left width 1

您得到的结果

I have gnuplot data file:

CS  31.73   18.32   20.78   22.88   1.97    1.29    0.90    2.01
FL  43.27   29.45   15.64   6.55    1.64    1.27    2.18    0.00
HB  32.44   20.43   14.89   14.53   5.42    10.92   0.80    0.31
HD  28.53   7.27    29.53   20.33   9.18    0.93    2.04    1.44
MR  22.56   36.19   10.66   15.51   9.45    4.32    0.80    0.31
ZK  27.15   10.81   27.40   16.10   8.05    7.24    1.06    1.71
All 30.00   21.35   18.05   16.82   6.14    5.39    1.11    0.85

And my gnuplot Script:

set term pos eps font 20
set style data histogram
set style histogram rowstacked
set key invert reverse above
set boxwidth 0.8
set format y "%.0f%%"
set border 3 
set yrange [0:100]
set size 0.9 , 1.8

set label 1 "1092" at -0.3,103 font "Times-Roman, 17" 
set label 2 "500" at 0.7,103 font "Times-Roman, 17" 
set label 3 "1000" at 1.8,103 font "Times-Roman, 17" 
set label 4 "500" at 2.8,103  font "Times-Roman, 17" 
set label 5 "1000" at 3.8,103 font "Times-Roman, 17" 
set label 6 "500" at 4.8,103 font "Times-Roman, 17" 
set label 7 "500" at 5.8,103 font "Times-Roman, 17" 


set output 'aspect.eps'
plot 'a3b-aspect' \
    using($2):xtic(1)   t "pattern 1"  lc rgb "#006600"  lt -1 fs pattern 1, \
''  using($3)           t "pattern 2"  lc rgb "#006600"  lt -1 fs pattern 2, \
''  using($4)           t "pattern 3"  lc rgb "#330000"  lt -1 fs pattern 3, \
''  using($5)           t "pattern 4" lc rgb "#000099"  lt -1 fs pattern 4, \
''  using($6)           t "pattern 5"  lc rgb "#000099"  lt -1 fs pattern 5, \
''  using($7)           t "pattern 6"   lc rgb "#000099"  lt -1 fs pattern 6, \
''  using($8)           t "pattern 7"  lc rgb "#000099"  lt -1 fs pattern 7, \
''  using($5)           t "pattern 3" lc rgb "#660000"  lt -1 fs pattern 3, \
''  using($6)           t "pattern 3"   lc rgb "#990000"  lt -1 fs pattern 3

Output:

I have to delete some space between legend(patterns above) and text. Could we custom rectangle size on that? and also invert my legend order... the bottom patterns in bar chart should be the first legend. Thanks

解决方案

The default justification of the legend key is Right which isn't appropriate when using reverse like you do: Set the Left option.

Optionally you can also increase or decrease the space reserved for the text with the width option.

To have to lower row appearing first, don't use the invert option.

So with the key settings

set key reverse above Left width 1

you get the result

这篇关于在堆叠的条形图中用文字设置图例/图案之间的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆