每个数据集的颜色不同

时间:2015-01-12 11:52:03

标签: colors indexing gnuplot

经过2天的试验和错误,我在这里寻求帮助,因为我完全迷失了gnuplot。 我想要的只是用命名列显示不同颜色的几个数据集。 结果如下:

result

第一个问题:图表上的线条颜色不同,但标题颜色相同。 第二个问题:如果我在专栏之后用列(-2)替换“idx”(即:

datafile index idx using "packetid":'mapping_dsn':(0):"mapping_length":(column(-2)) with vectors filled head size screen 0.008,145 lc palette z title sprintf("dataset %d", column(-2)) 

我有这个输出

second result

在我看来,idx和列(-2)应该是等价的? 这是gnuplot脚本的缩短版本(我相信最重要的部分):

stats datafile every ::2
set palette maxcolors 3
set palette defined ( 0 'green', \
                      1 'red', \
                      2 'blue' )

set key autotitle columnhead
set cbrange[0:STATS_blocks-1]

plot for [idx=0:STATS_blocks-1] \
    datafile index idx using "packetid":'mapping_dsn':(0):"mapping_length":(idx) with vectors filled head size screen 0.008,145 lc palette z title sprintf("dataset %d", idx)

我的数据格式由2个数据集组成,看起来像这样(我删除了一些数据以缩短数据):

packetid|time_delta|ip4src|ip4dst|ip6src|ip6dst|mptcpstream|tcpstream|subtype|tcpseq|mapping_ssn|mapping_length|mapping_dsn|ssn_to_dsn|dataack
2|0.000000000|192.168.1.1|192.168.1.2|||0|0|0|0|||||
5|0.000067000|192.168.1.1|192.168.1.2|||0|0|2|1|1|20|0||
6|0.000125000|192.168.1.1|192.168.1.2|||0|0|2|21|21|20|20||
8|0.000064000|192.168.1.1|192.168.1.2|||0|0|2|41|41|20|40||
9|0.000125000|192.168.1.1|192.168.1.2|||0|0|2|61|61|20|60||

packetid|time_delta|ip4src|ip4dst|ip6src|ip6dst|mptcpstream|tcpstream|subtype|tcpseq|mapping_ssn|mapping_length|mapping_dsn|ssn_to_dsn|dataack
2|0.000000000|192.168.1.1|192.168.1.2|||0|0|0|0|||||
5|0.000067000|192.168.1.1|192.168.1.2|||0|0|2|1|1|20|0||
6|0.000125000|192.168.1.1|192.168.1.2|||0|0|2|21|21|20|20||
8|0.000064000|192.168.1.1|192.168.1.2|||0|0|2|41|41|20|40||
9|0.000125000|192.168.1.1|192.168.1.2|||0|0|2|61|61|20|60||

来自christophe的消息之后编辑:虽然根据您的设备进行修改后仍然存在问题(线型0不存在所以我重新编制索引):

set linetype 1 lw 3 pt 3 lc rgb "red"
set linetype 2 lw 3 pt 3 lc rgb "green"

... datafile index idx using "packetid":'mapping_dsn':(0):"mapping_length":(idx+1) with vectors filled head size screen 0.008,145 lc variable title sprintf("Mappings from dataset %d", idx)

标题箭头全部为黑色(而不是红色和绿色): 3rd result

1 个答案:

答案 0 :(得分:2)

linecolor palette(以及linecolor variable)方法的问题是,线条颜色可能因单个图而异。当颜色规范对于所有点都是恒定时,Gnuplot并不考虑特殊情况。

要拥有正确的密钥,您必须将lc idx与循环索引idx一起使用:

plot for [idx=0:STATS_blocks-1] \
datafile index idx using "packetid":'mapping_dsn':(0):"mapping_length" with vectors filled head size screen 0.008,145 lc idx+1 title sprintf("dataset %d", idx)

关于column(-2) vs idx:在column(-2)声明之外使用using并不能正常运作。我认为这样做会产生错误。