2014-11-23 97 views
1

我有一個沿x軸的粒子位置的文本文件,每次碰撞後它都會發生變化。示例數據。Gnuplot 1d plot

0 7.5 10 30 30 40 
0 9.375 10 32.5 40 40 
0 10 10 33.3333 36.6667 40 
0 10.25 10.75 34 34 40 
0 11.0938 13.2812 28.75 40 40 

我目前正試圖使用​​GNU陰謀繪製數據。我想要它做的是沿x軸有這些點,但不是一次繪製整個文件,而是希望gnu圖一次繪製一條線。此外,所以數據是可識別的,我試圖將點標記爲大標記而不是點。我正在努力做到這一點,任何幫助將不勝感激。

回答

0

我不認爲你必須使用awk轉置數據,因爲每行已經包含單個粒子的數據。

因此,基於從DragonHu的代碼,我有這樣的: enter image description here

爲了產生這種情節,我還增加了線路連接的點。另外,我使用了特殊的列號0,它只是給出了數據文件中的行號,從0開始。

另一個技巧:使用反斜槓\,可以將命令拆分爲多行。這裏是我使用的繪圖命令:

plot "particle.dat" using 1:0 with points linetype 1 pointtype 7 pointsize 3 title "particle 1",\ 
"" u 1:0 notitle w l lt 1,\ 
"" u 2:0 w p lt 2 pt 7 ps 3 t "particle 2", \ 
"" u 2:0 notitle w l lt 2,\ 
"" u 3:0 w p lt 3 pt 7 ps 3 t "particle 3", \ 
"" u 3:0 notitle w l lt 3,\ 
"" u 4:0 w p lt 4 pt 7 ps 3 t "particle 4", \ 
"" u 4:0 notitle w l lt 4,\ 
"" u 5:0 w p lt 5 pt 7 ps 3 t "particle 5",\ 
"" u 5:0 notitle w l lt 5 

不過,這還不是答案,因爲問題是一次繪製一組點。這可以通過以下代碼來實現。它產生五個單地塊我傾倒入GIF動畫人物:

set key center 

set yrange[0:1] 
set xrange[0:40] 

set terminal gif size 600, 200 animate delay 100 

set output "animated.gif" 
do for [n=0:4] { 
    set title sprintf("Lineno. %d", n) 

    plot "particle.dat" every ::n::n using 1:(0) with points pointtype 7 pointsize 3 title "particle 1",\ 
    "" every ::n::n u 2:(0) w p pt 7 ps 3 t "particle 2", \ 
    "" every ::n::n u 3:(0) w p pt 7 ps 3 t "particle 3", \ 
    "" every ::n::n u 4:(0) w p pt 7 ps 3 t "particle 4", \ 
    "" every ::n::n u 5:(0) w p pt 7 ps 3 t "particle 5",\ 


} 
unset output 

如果應該被創建單個圖像,其經由

set terminal ongcairo 
do for [n=0:4] { 
    set title sprintf("Lineno. %d", n) 
    set output sprintf("PictureNumber_%d",n) 

    plot ... 
    unset output 


} 

enter image description here

可以
1

首先,使用AWK

awk '{for(i=1;i<=NF;i++)a[NR,i]=$i}END{for(i=1;i<=NF;i++){for(j=1;j<=NR;j++)printf a[j,i]"\t";printf "\n"}}' original.dat > particle.dat 
    #suppose that your input data is original.dat and the output data is particle.dat 

行轉換爲列轉換後的數據是:

set border 1 
    #`set border 1` means only showing the bottom border of the plot. see `help border` for more information 
set xtics nomirror 
    #only show the bottom tics on the x axis and suppress the upper tics of the x axis 
unset ytics 
    #suppress the tics on the y axis 
set key outside 
    #set the legend out side the plot 
plot "particle.dat" using 1:(1) with points pointtype 7 pointsize 3 title "particle 1", "" u 2:(2) w p pt 7 ps 3 t "particle 2", "" u 3:(3) w p pt 7 ps 3 t "particle 3", "" u 4:(4) w p pt 7 ps 3 t "particle 4", "" u 5:(5) w p pt 7 ps 3 t "particle 5" 
    #`using 1:(1)` means use the first column as X and a constant number of 1 as Y. see `help using` for more details 
    #`u` is short for `using`and `w p pt 7 ps 3` is short for `with points pointtype 7 pointsize 3. 

0 0 0 0 0 
7.5 9.375 10 10.25 11.0938 
10 10 10 10.75 13.2812 
30 32.5 33.3333 34 28.75 
30 40 36.6667 34 40 
40 40 40 40 40 

然後,在gnuplot的下面的代碼繪製數據

該圖的輸出是 enter image description here