2011-05-05 52 views
3

設置,我有以下數據文件:出圖從一個數據2系列中的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.%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顯示2個數據系列:每個服務器一個?

回答

5

我發現了一個soluton自己:

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 
+3

這裏的信息(替他人)這個解決方案的 「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來獲得相同的結果。 – neillb 2011-05-07 00:57:45

+0

@nellib,如果事先不知道系列的數量,你知道是否可以繪製幾個系列?即Server1 .. ServerN,其中N是可變的。 – 2011-05-07 07:30:13

+1

我不知道一個好方法。您可以預處理文件進行排序並將其分配到每個服務器的數據集中,當然也可以爲您自己的解決方案,您可以爲每個可能的服務器添加一個條件子句(假設你知道你的最大N,並且它不是巨大。在過去,我寫了一個(ruby)腳本來檢查數據文件並相應地生成gnuplot plot命令。有可能有更好的方法。您可以將「最多變量N」問題添加到原始問題中(作爲獎勵部分),以便更多人看到它。 – neillb 2011-05-07 12:13:56

相關問題