【问题标题】:Gnuplot : how to make a gif by plotting one block of data after the other in the same file .dat?Gnuplot:如何通过在同一个文件.dat中绘制一个数据块来制作gif?
【发布时间】:2021-10-26 15:49:15
【问题描述】:

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

   #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

【问题讨论】:

  • 数据是固定的还是可以改变的?您的数据有一个空行,是否可以更改为双空行?对于这两种情况都会有一些解决方案,后者可能会更容易。
  • 是的,数据可以更改(由 Fortran 程序生成)
  • 请问双空行数据的解决方案是什么?

标签: plot gnuplot gif


【解决方案1】:

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

注意:term gif 中的选项optimize 可能会导致颜色错误(参见:gnuplot: viewing angle dependent colors with 3D circles in GIF terminal) 因此,要么不优化所有帧,要么将所有帧导出为 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

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多