2017-10-14 90 views
-2

我的代碼返回1000 snapshot_XXXX.dat文件(XXXX = 0001,0002,...)。它們是兩列數據文件,用於拍攝我在特定時間運行的系統的照片。我想按照它們創建的順序將它們混合在一起來構建2D圖(或熱圖),以顯示隨時間推移的數量的演變。來自幾個輸入數據文件的2D圖

我該如何使用gnuplot來做到這一點?

+1

顯示您的當前代碼 – RomanPerekhrest

回答

0

假設要時間軸從底部到頂部,可以嘗試以下方法:

n=4 # Number of snapshots 

set palette defined (0 "white", 1 "red") 
unset key 
set style fill solid 

set ylabel "Snapshot/Time" 
set yrange [0.5:n+0.5] 
set ytics 1 

# This functions gives the name of the snapshot file 
snapshot(i) = sprintf("snapshot_%04d.dat", i) 

# Plot all snapshot files. 
# - "with boxes" fakes the heat map 
# - "linecolor palette" takes the third column in the "using" 
# instruction which is the second column in the datafiles 
# Plot from top to bottom because each boxplot overlays the previous ones. 

plot for [i=1:n] snapshot(n+1-i) using 1:(n+1.5-i):2 with boxes linecolor palette 

該實施例數據

snapshot_0001.dat snapshot_0002.dat snapshot_0003.dat snapshot_0004.dat 
1.0 0.0   1.0 0.0   1.0 0.0   1.0 0.0 
1.5 0.0   1.5 0.0   1.5 0.0   1.5 0.0 
2.0 0.5   2.0 0.7   2.0 0.7   2.0 0.7 
2.5 1.0   2.5 1.5   2.5 1.5   2.5 1.5 
3.0 0.5   3.0 0.7   3.0 1.1   3.0 1.5 
3.5 0.0   3.5 0.0   3.5 0.7   3.5 1.1 
4.0 0.0   4.0 0.0   4.0 0.0   4.0 0.7 
4.5 0.0   4.5 0.0   4.5 0.0   4.5 0.0 
5.0 0.0   5.0 0.0   5.0 0.0   5.0 0.0 

結果這個圖像(的Gnuplot 5.0測試)中:

evolution with time from bottom to top

您可以更改訂單如果你想從頂部到底部的情節的情節。如果你想從左到右,也許this可以幫助(未測試)。

+0

謝謝,這對我來說是一個很好的起點。 (':(n + 1.5-i):')plot命令中的第二列是什麼意思?而且,我可以使用更多顏色的調色板嗎?我通常用8種顏色代替2. – ManyBertin

+0

'1:(n + 1.5-i):2'表示'x:y:color',也就是說,y值(時間)是從快照數('n'是快照的總數,'i'是當前繪製的快照的編號,相應的行將出現在'y = n + 1.5-i'處)。有關配置調色板的顏色,請參閱「幫助調色板」或搜索www中的一些示例。 – maij

+0

太棒了。非常感謝 – ManyBertin

相關問題