gnuplot 使用 3d plot 绘制一些图像的问题

Problems with gnuplot to plot some images with 3d plot

所以我编写了一些代码来在球面上打印一些点,我也让他定位了所有打印点的质心位置(每次他打印一个点时,他都会重新计算位置质心)。质心的位置被打印到一个文件中,其中包含 i(这是直到此时打印的点数)和坐标 x、y 和 z。根据我的一位教授制作的脚本,我用 gnuplot 在 运行 下面制作了这个脚本,用一个围绕质心位置移动的球制作一排图像,并在最后的 i 可以制作带有图片的视频。

set terminal pngcairo size 1080,1080

set view equal xyz
fx(t)= system(sprintf("sed -n '%d p' ../dat/cm.dat | cut -f2 -d' '", t))
fy(t)= system(sprintf("sed -n '%d p' ../dat/cm.dat | cut -f3 -d' '", t))
fz(t)= system(sprintf("sed -n '%d p' ../dat/cm.dat | cut -f4 -d' '", t))
unset xtics
unset ytics
unset ztics

t= 1
while(t <= 100000){
    set output sprintf("%d.png", t/10)
    set object circle at fx(t), fy(t), fz(t) size 0.35 fc rgb "#000000" fillstyle solid 1.0
    splot "../dat/cm.dat" u 2:3:4 w l lc rgb "#FFFFFF" t""
    unset object
    t= t+10
}
unset terminal
unset output

谁把我带到这里来的问题,我尝试了所有我想不到的事情,但每次我 运行 脚本都会打印出应该围绕质心位置移动的球,如此之大那几乎不可能看到运动,你可以看到尺寸here的问题。因此,如果有人知道问题出在哪里,我将不胜感激。

p.s.: 也许这根本不重要,但很抱歉我的写作我不太熟悉英语。

您首先必须设置输出然后绘图。

...
set output sprintf("%d.png", t/10)
splot "../dat/cm.dat" u 2:3:4 w l lc rgb "#FFFFFF" t""
...

加法:

我想我还是不明白你的问题。 到目前为止,我的理解是:您有一个包含列的巨大数据文件:i,x,y,z。并且 x,y,z 描述了 3D 运动。最后你想用球体或圆圈来动画这个运动,对吗?你的问题是这个球体太大了?然后缩小尺寸,例如而不是 size 0.35 试试 size 0.05.

也许通过以下(不同的)示例,我们会(迭代地)更接近您想要的。 顺便说一句:

  1. 我觉得不需要sed,可以用gnuplot
  2. 您可以使用 gnuplot 创建动画 GIF

这只是一个猜测,我可能走错了路。请告诉我。

代码:

### animated movement in 3D
reset session

set term gif animate delay 10 optimize
set output "myAnimation.gif"

# create some test data
set print $Data 
    x0 = y0 = z0 = 0
    do for [i=1:200] {
        x0=x0+rand(0)-0.5; y0=y0+rand(0)-0.5; z0=z0+rand(0)-0.5
        print sprintf("%d %.3f %.3f %.3f",i,x0,y0,z0)
    }
set print

do for  [i=0:199] {
    splot $Data u 2:3:4 w l lc rgb "blue" notitle, \
          '' u 2:3:4 every ::i::i w p pt 7 ps 2 lc rgb "red" notitle
}
set output
### end of code

结果: