2017-04-18 140 views
2

我有以下data.dat文件集羣條形圖

A B C D E 
1 24 24 1 5.06326e-05 
1 12 12 2 9.82645e-05 
1 6 6 4 0.000178653 
1 3 3 8 0.000326006 
2 48 24 1 2.92298e-05 
2 24 12 2 6.06926e-05 
2 12 6 4 0.000102249 
2 6 3 8 0.000184589 

,我想生成使用E列數據和對AD列數據的羣集柱狀圖。 A是羣集編號,D爲每個羣集重複。我設法去接近最終的解決方案,我用

p "data.dat" u 5:key(1) 

獲得 enter image description here

不過雖然數據是正確的,集羣沒有得到很好的後可見。有沒有一種方法可以在不改變數據格式的情況下使用集羣來繪製這個圖?

回答

1

我會說這也取決於你想處理的一般輸入。在該列D始終包含的2每個簇連續功率的情況下,人們可能會傾向於與boxes繪圖樣式手動構造的框:

set terminal pngcairo enhanced 
set output 'fig.png' 

#if your data file contains the header line with A, B, C, D, E 
set key autotitle columnhead 

set boxwidth 0.5 
set style fill solid 

f=6 
w=0.5 

unset key 
set style fill empty 

unset xtics 
set ytics out nomirror 

set format y '%.2f' 
set label at graph 0,1 "{/Symbol \264}10^{3}" offset character 0.75,-1 
plot \ 
    'data.dat' u ($1*f*w + log($4)/log(2)*w):($5/1e-3) w boxes lc rgb 'dark-red', \ 
    '' u ($1*f*w + log($4)/log(2)*w):(0):4 w labels offset 0, char 1 

這裏,變量w指定與一個基本的期望框。每個方框的位置計算爲整個集羣的偏移量$1*f*w加上特定方框log($4)/log(2)*w的偏移量。如果欄D包含數字1,2,4,8等,則log($4)/log(2)給出該框在對應羣集內的「位置」。結果是: enter image description here

或者,另一個假設可能是每個簇具有相同數量的框G。然後腳本可能看起來像:

set terminal pngcairo enhanced 
set output 'fig.png' 

#if your data file contains the header line with A, B, C, D, E 
set key autotitle columnhead 

set boxwidth 0.5 
set style fill solid 

f=6 
w=0.5 
G=4 

unset key 
set style fill empty 

unset xtics 
set ytics out nomirror 

set format y '%.2f' 
set label at graph 0,1 "{/Symbol \264}10^{3}" offset character 0.75,-1 
plot \ 
    'data.dat' u (int($0/G)*f*w + (int($0)%G)*w):($5/1e-3) w boxes lc rgb 'dark-red', \ 
    '' u (int($0/G)*f*w + (int($0)%G)*w):(0):4 w labels offset 0, char 1 

的簇號爲int($0/G)使用特殊的列數0(給在輸入數據文件中的從零開始的行數)來計算。以類似的方式,int($0)%G產生其集羣內特定框的位置。