【问题标题】:gnuplot animation multiple data files hold on after do loopgnuplot动画多个数据文件在do循环后保留
【发布时间】:2020-08-06 18:26:25
【问题描述】:

我正在从两个数据文件制作动画。

我需要在第一个循环之后“等待”,然后重新绘制第二个循环进行动画。

看下面的例子:

set term gif size 400,400 animate delay 100 loop 0 optimize font 'Verdana,10' crop
set output "output.gif"
set yrange [0:4]                                        
set xrange [0:5]

$data1 << EOD
2.24448 0.270645    1.00    1.00
3.24448 0.270645    0.500   1.20
1.24448 0.411645    0.600   1.60
EOD

$data2 << EOD
3.24448 2.50645    0.400    1.00
0.24448 2.30645    0.800   1.20
1.24448 2.50000    0.300   0.60
1.55448 2.21645    0.300   1.30
EOD

stats $data1 using 1:4 nooutput
n1 = int(STATS_records) - 1

stats $data2 using 1:4 nooutput
n2 = int(STATS_records) - 1

plot x

do for [i=0:n1] {
    replot $data1 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "red" notitle
}

do for [i=0:n2] {
    replot $data2 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "blue" notitle
}

set output

输出如下:红色向量是从data1创建的,蓝色向量是从data2创建的。

我想先为红色矢量设置动画,然后再开始为蓝色矢量设置动画。就目前而言,当蓝色矢量出现时,红色矢量消失并重新出现。我只想简单地开始一个一个地为红色向量设置动画,然后是蓝色向量。

见下图:红色矢量按计划出现,但是蓝色矢量一出现,红色矢量消失然后开始动画,我只想按照顺序,先绘制红色矢量并按住,然后继续动画蓝色向量。

【问题讨论】:

    标签: animation gnuplot animated-gif


    【解决方案1】:

    我猜replot 有一个特殊的行为......(但我不记得细节)。 因此,我会在没有replot 的情况下这样做。

    代码:

    ### animated vectors
    reset session
    set term gif size 400,400 animate delay 100 optimize font 'Verdana,10' crop
    set output "output.gif"
    set yrange [0:4]
    set xrange [0:5]
    
    $data1 << EOD
    2.24448 0.270645    1.00    1.00
    3.24448 0.270645    0.500   1.20
    1.24448 0.411645    0.600   1.60
    EOD
    
    $data2 << EOD
    3.24448 2.50645    0.400    1.00
    0.24448 2.30645    0.800   1.20
    1.24448 2.50000    0.300   0.60
    1.55448 2.21645    0.300   1.30
    EOD
    
    stats $data1 using 1:4 nooutput
    n1 = int(STATS_records) - 1
    
    stats $data2 using 1:4 nooutput
    n2 = int(STATS_records) - 1
    
    plot x
    
    do for [i=0:n1] {
        plot x, \
        $data1 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "red" notitle
    }
    
    do for [i=0:n2] {
        plot x, \
        for [j=0:n1] $data1 u 1:2:3:4 every ::0::j w vectors lw 1.5 lc rgb "red" notitle, \
        $data2 u 1:2:3:4 every ::0::i w vectors lw 1.5 lc rgb "blue" notitle
    }
    set output
    ### end of code
    

    结果:

    添加:(合并 3 个或更多文件)

    数据:

    File1.dat

    2.24448 0.270645    1.00    1.00
    3.24448 0.270645    0.500   1.20
    1.24448 0.411645    0.600   1.60
    

    File2.dat

    3.24448 2.50645    0.400    1.00
    0.24448 2.30645    0.800   1.20
    1.24448 2.50000    0.300   0.60
    1.55448 2.21645    0.300   1.30
    

    File3.dat

    4.0  1.0  -1.0   1.0
    1.0  2.0   0.5   0.7
    4.0  3.0  -1.0  -0.5
    1.0  3.0   0.5  -1.0
    

    代码:

    ### animated vectors from several files
    reset session
    set term gif size 400,400 animate delay 100 optimize font 'Verdana,10' crop
    set output "output.gif"
    set yrange [0:4]
    set xrange [0:5]
    
    set table $Arrows
        plot 'File1.dat' u 1:2:3:4:('0xff0000') w table
        plot 'File2.dat' u 1:2:3:4:('0x0000ff') w table
        plot 'File3.dat' u 1:2:3:4:('0x00ff00') w table
    unset table
    
    plot x
    
    do for [i=1:|$Arrows|] {
        plot x, \
        $Arrows u 1:2:3:4:5 every ::0::i-1 w vec lw 1.5 lc rgb var notitle
    }
    set output
    ### end of code
    

    结果:

    【讨论】:

    • 实际上,另一种解决方案是合并数据块并为颜色添加一列。然后用linecolor variable绘制这个单一的数据块。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    • 2022-10-14
    • 2020-05-13
    • 1970-01-01
    相关资源
    最近更新 更多