从gnuplot中的一个数据集绘制2个系列

And*_*ich 3 gnuplot

我有以下数据文件:

Time;Server;Hits
2011.05.05 12:00:01;Server1;12
2011.05.05 12:00:01;Server2;10
2011.05.05 12:00:02;Server1;2
2011.05.05 12:00:02;Server2;4
Run Code Online (Sandbox Code Playgroud)

所以,到目前为止,我已经提出了以下gnuplot脚本:

set datafile separator ";"
set autoscale
set xdata time
set timefmt "%Y.%m.%d %H:%M:%S"
set xtics rotate 
set term png 
set output "hits.png"
set style fill solid 0.5
plot "hits.log" using 1:3 title 'Hits'
Run Code Online (Sandbox Code Playgroud)

但是,那个数据来自同一图表上的两个服务器的数据作为一个数据系列.如何让gnuplot显示2个数据系列:每个服务器一个?

And*_*ich 5

我自己找到了一个解决方案:

plot "hits.log" using 1:(stringcolumn(2) eq "Server1" ? $3 : 1/0) title 'Server1' with lines,\
     "hits.log" using 1:(stringcolumn(2) eq "Server2" ? $3 : 1/0) title 'Server2' with lines
Run Code Online (Sandbox Code Playgroud)

  • 以下是该解决方案"1/0"核心的信息(针对其他人):来自[手册](http://www.gnuplot.info/docs_4.2/gnuplot.html#dx1-52001)"整数表达式"1/0"可用于生成"未定义"标志,这会导致忽略一个点; [三元运算符](http://www.gnuplot.info/docs_4.2/gnuplot.html#x1-5800013.2 .3)给出一个例子.或者你可以使用预定义的变量NaN来实现相同的结果." (3认同)