【发布时间】:2011-08-28 00:14:32
【问题描述】:
扩展我之前提出的问题,可以在此处找到,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) 和 (x2,y2) 之间,该文件将持续到 (x10,y10)。在 (x1,y1) 和 (x2,y2) 之间的曲线中;第二个文件中的点 (x1,y1)、(x2,y2) 和 (x3,y3) 位于。
我点击此链接http://t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html 对这两个文件进行排序和连接,但得到了一些完全错误的奇怪行。这些值实际上应该绘制 Bezier 曲线,但没有得到图形。我编写了以下 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!
【问题讨论】:
-
检查我是否理解您的问题:如果您将两个文件放在一个文件中,您只需绘制数据。棘手的部分是如何在不事先合并这些文件的情况下使用 gnuplot 做到这一点。这是正确的还是有“更多”的?
-
@Woltan 感谢您查看我的问题。最后我得到了回复。是的,这绝对正确。我觉得自己很愚蠢,我不能这样想。如果它们可以合并到一个文件中,那么 gnuplot 将简单地绘制它而没有任何麻烦。问题是,我在我的 python 代码中生成这些文件。因此,如果在 python 中有一种方法可以合并两个文件并在连接的文件中对它们进行排序,那么就可以了。
-
好吧,我想我找到了答案。但据我所知,我已经尝试过,但会再试一次。我会关注这个t16web.lanl.gov/Kawano/gnuplot/datafile3-e.html
-
现在我记得,我已经尝试过排序和连接,但这并没有给我正确的结果。我应该从数据中得到贝塞尔曲线,但得到了一些错误的随机线。
-
当有多个条目时,例如
x=0.12,您可能会遇到问题。既然您使用 python 导出它,为什么不简单地更改导出例程并编写一个没有多个条目的文件?你也可以使用matplotlib
标签: gnuplot