Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gnuplot1d图_Gnuplot - Fatal编程技术网

gnuplot1d图

gnuplot1d图,gnuplot,Gnuplot,我有一个x轴上粒子位置的文本文件,每次碰撞后都会发生变化。示例数据 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 plot绘制数据。我想要它做的是沿着x轴绘制这些点,但不是一次绘制整个文件,我希望

我有一个x轴上粒子位置的文本文件,每次碰撞后都会发生变化。示例数据

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 plot绘制数据。我想要它做的是沿着x轴绘制这些点,但不是一次绘制整个文件,我希望gnu plot一次绘制一条线。此外,数据是可识别的,我试图将点绘制为大标记,而不是点。我正在努力做到这一点,任何帮助都将不胜感激

首先,使用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
然后,使用gnuplot中的以下代码绘制数据:

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.
绘图的输出为

我认为您不必使用
awk
对数据进行转置,因为每一行已经包含单个粒子的数据

因此,根据龙虎的代码,我有:

为了生成这个图,我还添加了连接点的线。另外,我使用了特殊的列号0,它只给出数据文件中的行号,从0开始

另一个技巧是:使用反斜杠
\
,可以将命令拆分为多行。以下是我使用的plot命令:

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


 }

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

     plot ...
     unset output


 }