Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从gnuplot中的一个数据集绘制2个系列_Gnuplot - Fatal编程技术网

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

从gnuplot中的一个数据集绘制2个系列,gnuplot,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 到目前为止,我已经提出了以下gnuplot脚本: set datafile separator ";" set autoscale set xdata time set timefmt "%Y.%m.

我有以下数据文件:

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
到目前为止,我已经提出了以下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'

但是,这一个将来自两台服务器的数据绘制在同一个图形上,作为一个数据系列。如何使gnuplot显示两个数据系列:每台服务器一个?

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

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

下面是关于此解决方案“1/0”核心的信息(供其他人参考):从“整数表达式”中,可以使用“1/0”生成“未定义”标志,这会导致忽略一个点;给出了一个示例。或者您可以使用预定义变量NaN来实现相同的结果。“@nellib,如果事先不知道系列的数量,您知道是否可以绘制多个系列吗?i、 e.服务器1。。服务器N,其中N是变量。我不知道一个好方法。您可以对文件进行预处理,对其进行排序并将其分隔到每个服务器的数据集中,当然,您也可以在自己的解决方案中为每个可能的服务器添加一个绘图子句(糟糕!),前提是您知道max N,并且它不是很大。在此之前,我编写了一个(ruby)脚本来检查数据文件并相应地生成gnuplot plot命令。可能有更好的办法。您可以将“最多变量N”问题添加到原始问题中(作为额外部分),以便更多人看到它。@nellib,谢谢您的评论。我最终通过创建一个perl脚本做了类似的事情。