2017-07-30 69 views
1

我有一個包含不同數量級的列的數據文件。我想將所有具有相似數量級的列集體繪製在同一個畫布上。我這樣做是通過使用stats命令測試每列的最大值。Gnuplot:在繪圖畫布之間切換

我試過到目前爲止

set key autotitle columnheader 
set terminal pdfcairo 
set out 'test.pdf' 

do for [col=5:125] { 
    stats 'datafile' using col nooutput 
    if(STATS_max < 1e-7) { 
    #draw to canvas 1 
    plot 'datafile' using 1:col with lines 
    } else { 
    if(STATS_max < 1e-6) { 
     #draw to canvas 2 
     plot 'datafile' using 1:col with lines 
    } else { 
     #draw to canvas 3 
     plot 'datafile' using 1:col with lines 
    } 
    } 
} 

但未能解決尚未畫布之間進行切換的問題。

文件看起來像(第一行是標題):

time 5.000/5.000 5.000/4.000 ... 
1e-5 7.6e-23  3.057e-17  ... 
0.002 3.4e-17  5.2e-13  ... 
.  .    .   . 
.  .    .    . 
.  .    .    . 

有沒有辦法實現這種行爲,如果是,怎麼樣? 在此先感謝。

回答

0

您可以先將相應的列號組合成單獨的變量,然後在腳本的最後部分繪製所有內容。例如,對於test.dat爲:

1 10 11 100 101 1000 1001 
2 20 21 200 201 2000 2001 
3 30 31 300 301 3000 3001 
4 40 41 400 401 4000 4001 
5 50 51 500 501 5000 5001 

下面地塊只有「第一組」的腳本,即,列2和3:

fName = 'test.dat' 

set terminal pngcairo 
set out 'fig.png' 

#max. column number in the datafile 
N = 5 

#inspired by https://stackoverflow.com/a/35729052/5351549 
_group_1 = "" 
_group_2 = "" 
_group_3 = "" 

groupAppend(idx, col) = sprintf("_group_%d = _group_%d . \" %d\";", idx, idx, col) 

do for [col=2:N] { 
    stats fName using col nooutput 
    if(STATS_max < 1e2) { 
     eval groupAppend(1, col) 
    } else { 
     if(STATS_max < 1e3) { 
      eval groupAppend(2, col) 
     } else { 
      eval groupAppend(3, col) 
     } 
    } 
} 

plot for [i in _group_1] fName u 1:int(i) w l t sprintf("column %s", i) 

隨着gnuplot的較新的版本,一個然後可以使用數組來保存列索引,而不是以間接方式將它們以空格分隔的方式存儲爲字符串。

+0

完美地工作。謝謝! – camelCase