Gnuplot标签在不同形状的列中

时间:2017-04-02 19:50:20

标签: gnuplot

我有点问题。我尝试使用许多线条或形状创建gnu图,但标题位于最后一列。文件中的示例数据

18:40:03    0.00 K/s    3.65 K/s  0.00 %  0.25 % AA
18:40:03    0.00 K/s   69.44 K/s  0.00 %  0.05 % BB 
18:40:03     0.40 K/s    0.00 K/s  0.00 %  0.03 % AA

我的gnuplot代码

set xlabel "Date\nTime"
set timefmt "%H:%M:%S"
set format x "%H:%M:%S"
set xdata time
set autoscale  xy
set term png
set output "io.png"
plot 'io.log' using 0:8 title 'title', \
     '' using 0:8:10 with labels offset 0,char 1
~

但是我想创建一个情节,这个类型(AA)具有相同的颜色或形状,与BB CC不同......

fiddle

中的

1 个答案:

答案 0 :(得分:1)

为了简化操作,我们假设输入数据存储在文件test.dat中,并且具有以下形式:

1   2   AA
2   4   BB
3   6   AA

然后,有几种可能性可以根据第三列中标签的值来区分样式。

例如,可以调用外部处理来过滤掉“特殊类型”的记录(在您的情况下标记为“AA”)并指定特定样式:

unset key
set xr [0:4]
set yr [0:10]

plot \
    '< gawk ''$3=="AA"'' test.dat' using 1:2 w p pt 1, \
    '' u 1:2:3 w labels offset 0,char 1 tc rgb 'red', \
    '< gawk ''$3!="AA"'' test.dat' using 1:2 w p pt 2, \
    '' u 1:2:3 w labels offset 0,char 1 tc rgb 'blue'

这会产生: enter image description here

或者,为了区分标签的样式,可以直接在Gnuplot中过滤个别情况:

set terminal png enhanced
set output 'fig2.png'

unset key
set xr [0:4]
set yr [0:10]

checkLabel(label)=(label eq 'AA')
filter(label, val, flag)=(((flag && checkLabel(label))||(!flag && !checkLabel(label)))?val:1/0)

plot \
    'test.dat' using 1:2 w p , \
    '' using 1:(filter(stringcolumn(3), $2, 1)):3 w labels offset 0,char 1 tc rgb 'red', \
    '' using 1:(filter(stringcolumn(3), $2, 0)):3 w labels offset 0,char 1 tc rgb 'blue'

产生: enter image description here