每个数据集的不同颜色

Different color per dataset

经过 2 天的尝试和错误,我在这里寻求帮助,因为我完全迷失了 gnuplot。 我想要的只是用不同的颜色显示一些数据集,其中包含命名的列。 这是结果:

第一个问题:图表上的线条颜色不同,但标题中的颜色相同。 第二个问题:如果我用 column(-2) 替换 plotline 之后的 "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)) 

我得到了这个输出

在我看来 idx 和 column(-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)

标题箭头都是黑色的(而不是红色和绿色):

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)idx:在 using 语句之外使用 column(-2) 无法正常工作。我认为这样做应该会报错。