Gnuplot:如何通过在同一文件 .dat 中一个接一个地绘制数据块来制作 gif?

Gnuplot : how to make a gif by plotting one block of data after the other in the same file .dat?

我想从文件制作一个 gif data.dat:

   #x                     y                  z                   radius              color
#set 1
   222.333710          505.354645         -2938.58545          10.0000000          1.00000000         
   854.180481          64.3471069         -2844.13477          12.5992117          53.0000000    
  -109.606003          173.377197         -2975.83960          17.0997639          55.0000000       

#set 2
  0.746170461        -0.868437707         -2876.14355          123.856239          2001.00000    

#set 3   
   1.56590324E-02      6.23370660E-03     -2870.87378          129.126297          4001.00000          

我想在每个时间步绘制:

splot "data.dat" using 1:2:3:4:5 with circles lc var notitle

每组。意思是在时间 1 绘制集合 1,在时间 2 绘制集合 2,依此类推。

如何绘制直到定义的线已经被问到的问题here。 但是怎么可能画到一条不知道的线呢?我的想法是编写代码直到出现空白行,但我愿意接受任何建议。

最终,为了创建 .gif 我会写:

reset session

set term gif size 700,700 animate delay 30 optimize
set output "data.gif"

set xrange [-1000:1000]
set yrange [-1000:1000]
set zrange [-3000:-2500]

do for [a=1:3:1] {

###### code for splot
    
}
set output

如果您用两个空行分隔您的集合,您可以通过 index 轻松解决它们(检查 help index)。如果您不知道组(或块)的数量,您可以执行 stats(检查 help stats)。 您将在变量 STATS_blocks 中找到块数(要查看所有变量类型 show var STATS)。检查以下示例作为进一步优化的起点。

注意:term gif中的选项optimize可能会导致颜色错误(参见:) 因此,要么不要优化所有帧,要么将所有帧导出为 PNG(例如通过 term pngcairo)并使用其他软件从中创建动画 GIF。

代码:

### create animation from unknown number of sub-blocks
reset session
set term gif size 400,400 animate delay 100
set output "SO68940970.gif"

# create some random test data
set print $Data
    print "#x y z radius color
    SetCount = int(rand(0)*6)+10
    do for [b=1:SetCount] {
        print sprintf("#set%d",b)
        LineCount = int(rand(0)*5)+2
        do for [a=1:LineCount] {
            print sprintf("%g %g %g %g %g", \
              rand(0)*2000-1000,rand(0)*2000-1000,rand(0)*500-3000, \
              rand(0)*100+50, rand(0)*0xffffff)
        }
        if (b<SetCount) { print ""; print "" }  # two empty lines
    }
set print

stats $Data u 1 nooutput
N = STATS_blocks
print N

set xrange [-1000:1000]
set yrange [-1000:1000]
set zrange [-3000:-2500]
set ztics 250
set view equal xyz

set style fill solid 1.0
do for [i=1:N] {
    set title sprintf("Set %d",i)
    splot $Data u 1:2:3:4:5 index i-1 w circles lc rgb var notitle 
}
set output
### end of code

结果: