2011-08-28 73 views
2

绘制延长前,我才问这个问题可以在这里,plotting multiple (x,y) co-ordinates in a single curve with gnuplot发现。我试图用2个不同的文件在gnuplot中绘制贝塞尔曲线。第一个文件中的每个(x,y)形成一条穿过第二个文件中点的贝塞尔曲线。第一个文件具有坐标如下所示:合并多个数据文件,以一个单一的图形

x  y 
0.0 0.5  
0.12 0.1  
0.16 0.4  
0.2 0.35 
0.31 0.8  
0.34 0.6 
0.38 1.0  
0.46 0.2 
0.51 0.7  
0.69 0.9  

第二个文件具有坐标如下所示:

x  y 
0.00 0.7 
0.04 0.74073082208 
0.08 0.85926917792 
0.12 0.9 
0.16 0.9 
0.2 0.9 
0.24 0.749720623086 
0.28 0.874229601255 
0.32 0.74073082208 
0.36 0.8 
0.4 0.721178508605 
0.44 0.878821491395 
0.48 0.761772990545 
0.52 0.700774803388 
0.56 0.723771273415 
0.6 0.789508073675 
0.64 0.864014272269 
0.68 0.896743348931 

现在,我该如何合并这两个文件绘制单个图形。这两个文件没有相同的行数,但我想这并不重要。第一条曲线将是(X1,Y1)和这将持续至(X10,Y10)的第一个文件(x2,y2)之间。在(x1,y1)和(x2,y2)之间的曲线中;来自第二文件的点(x1,y1),(x2,y2)和(x3,y3)。

我跟着这个链接http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html进行排序和将两者连接起来的文件,但得到了一些奇怪的线,是完全错误的。这些值实际上应该绘制贝塞尔曲线,但不能得到图形。我写了下面的gnuplot脚本绘制连接数据:

set term x11 persist 
set title "Animation curves" 
set xlabel "Time (secs.)" 
set ylabel "Parameter" 
set x2label "Phoneme1" offset -35 
set pointsize 2 
set key off 
set style line 2 lt 0 lc 1 lw 2 
set xrange [0.0:1.0] 
set yrange [0.0:1.3] 

plot [0.0:0.8] "< cat -n file1.dat" u 1:2 smooth csplines ls 1, "" u 1:(0.0):(0):(1.3) w vectors nohead ls 2, "" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels, \ 
      "file1.dat" u 1:2 with points, \ 
      "file2.dat" u 1:2 with points, \  

我得到了以下错误:

plot "< cat -n file1.dat" u 1:2 smooth csplines ls 1, "" u 1:(0.0):(0):(1.3) w vectors nohead ls 2, "" u ($1+0.005):(1):(sprintf("P %d", $0)) w labels, "file1.dat" u 1:2 with points, "file2.dat" u 1:2 with points,     
         ^
"plot.gp", line 21: Cannot smooth: no data within fixed xrange! 
+0

要检查,如果我明白你的问题:如果你想在一个文件中的两个文件,你会简单地绘制数据。棘手的部分是如何用gnuplot做到这一点,而无需事先合并这些文件。这是正确的还是有“更多”的呢? – Woltan

+0

@沃尔坦谢谢你看我的问题。最后我得到了答复。是的,这是绝对正确的。我感到很蠢,我不能这样想。如果可以将它们合并到一个文件中,那么gnuplot就可以简单地绘制它,而不会有任何麻烦。事情是,我在我的python代码中生成这些文件。因此,如果在python中有合并两个文件并将它们排序在连接文件中的方法,那么这就可以实现。 – zingy

+0

嗯,我想我找到了答案。但据我所知,我已经尝试过,但会再试一次。我会按照这个http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html – zingy

回答

4

下面的脚本作品在我的机器上。这也许是连你在找什么...

set term x11 persist 
set title "Animation curves" 
set xlabel "Time (secs.)" 
set ylabel "Parameter" 
set x2label "Phoneme1" offset -35 
set pointsize 2 
set key off 
set style line 2 lt 0 lc 1 lw 2 
set xrange [0.0:1.0] 
set yrange [0.0:1.3] 

plot [0.0:0.8] "< cat file1.dat file2.dat | sort -n" u 1:2 smooth csplines ls 1, \ 
         "" u 1:(0):(0):2 w vectors nohead ls 2, \ 
         "" u ($1 + 0.005):(1):(sprintf("P %d", $0)) w labels, \ 
         "file1.dat" u 1:2 w p, \ 
         "file2.dat" u 1:2 w p 
+0

好的会尝试这个。 – zingy

+0

这工作。我可以看到我犯了一些语法错误。 – zingy

+0

我在想,并试图做一个错误的解决方案。尽管现在没有语法错误。但这并不是正确的方式。它只应绘制file1.dat中各点之间的曲线。来自file2.dat的数据是来自file1.dat的曲线之间的点。 – zingy

相关问题