2016-08-09 29 views
1

在Gnuplot中,我使用直方圖(聚集),但並非所有數據點都有有效值。在那些地方,我想用垂直文字替換欄中的「無法服務」。我該怎麼做?在直方圖(聚集)中,如何根據條件將垂直文本置於某些條的位置?

我當前的代碼:

set style data histogram 
set style histogram cluster gap 2 
set boxwidth 0.9 
set xtic rotate by -45 scale 0 

set output "test.pdf" 
plot 'data.txt' using 2:xtic(1) fs pattern 1 ti col, '' u 3 fs pattern 2 ti col 

數據文件包含:

類型 「磁性」, 「電」
「高負荷」 12000 12721.033920
「MED負荷」 15620.011886 15783.706215
「低負荷」15636.000000 16254.000000

+0

如何,沒有有效的值的文件是什麼樣子?這個在任何地方都有有效值,只有你必須'設置yrange [0:*]'來查看「高負載」欄。答案取決於這些無效值的樣子。 – Miguel

+0

「無效」值將看起來像「NaN」或「Na」而不是數字。 – Ron

+0

對不起,我不能找出這一個沒有一些非常hacky解決方案... – Miguel

回答

1

這是一個超級哈克的方式來做到這一點。我修改了文件,添加一個「南」:

"high load" NaN 12721.033920 
"med load" 15620.011886 NaN 
"low load" 15636.000000 16254.000000 

現在我繪製每個框的位置相對於其中的記錄出現在數據文件(列0)的順序計算的一切with boxes。這裏是「手動」定義的,但您應該能夠編寫一個函數,該函數根據從stats獲取的記錄數和每個記錄的列數獲取xrange和方框分隔。 boxwidth也取決於這些值。

set xtic rotate by -45 scale 0 
ymax = 20000 
set yrange [0:ymax] 

nrecords = 3 
ncolumns = 2 

set xrange [0:nrecords+1] 

# Calculate boxwidth from available space per column 
gap = 1./ncolumns/5. 
width = 1./ncolumns/2.-gap/2. 
set boxwidth width 

plot "data.txt" u ($0+1.-width/2.-gap/2.):($2) w boxes t "data1", \ 
    "" u ($0+1.+width/2.+gap/2.):($3) w boxes t "data2", \ 
    "" u ($0+1.):(ymax/6.):(stringcolumn(2) eq "NaN" ? \ 
    "Cannot serve" : ""):xtic(1) w labels rotate by 90 offset \ 
    first -width/2.-gap/2.,0 not, \ 
    "" u ($0+1.):(ymax/6.):(stringcolumn(3) eq "NaN" ? "Cannot serve" \ 
    : ""):xtic(1) w labels rotate by 90 offset first width/2.+gap/2.,0 not 

enter image description here