【问题标题】:Gnuplot: Making a gif of a map generated with matrix?Gnuplot:制作用矩阵生成的地图的 gif?
【发布时间】:2021-06-26 20:23:40
【问题描述】:

我生成了一个包含 100 个 15x15 矩阵的 .dat 文件,现在我想创建一个 gif 来显示从第一个矩阵到最后一个矩阵的演变。它们都是 1 或 -1 的矩阵,所以如果我想表示初始矩阵,我可以将其复制并粘贴到另一个文件中,然后将其放入 gnuplot:

plot 'firstmatrix.dat' matrix with image

It represents the 1, -1 matrix with yellow and black.

要创建 gif,我尝试在 gnuplot 中执行此操作:

set terminal gif animate delay 20
set output 'evolution.gif'
set xrange [0:15]
set yrange [0:15]
N=15
nframes=5
do for [i=1:int(nframes)] {
  plot 'evolution.dat' every ::(i-1)*N+1::i*N matrix with image
}

我打算从文件的第一行读取到第 15 行,然后从第 16 行到第 30 行,依此类推。

我只放了 5 帧以查看更好的结果,我发现 gif 在第一帧中显示了第一个矩阵,仅此而已,只有白色帧。

错误消息是 次这个:

warning: Skipping data file with no valid points

所以第一帧的数据,第一个矩阵,得到了很好的处理,但其余的则没有。所以这是我的问题,我不知道为什么它处理好第一个而不再处理。

提前致谢。

It shows only the first matrix in the first frame

【问题讨论】:

  • 问题解决了吗?回答可以接受吗?任何反馈将不胜感激。
  • 对不起,我想对您的答案进行更多研究以尝试添加一些内容,但是几天过去了,我忘了这样做。问题已解决,非常感谢,非常感谢您向我解释得如此详细,我可以向您保证,这对我很有帮助。
  • 好的。很高兴听到。然后请检查答案为接受,说明问题已解决。

标签: matrix plot gnuplot gif


【解决方案1】:

你已经很接近了。但它也花了我一些迭代和测试...... 显然,从矩阵中分割一行行需要every :::rowFirst::rowLast(注意开头的 3 个冒号)。然后 gnuplot 显然将整个矩阵的行索引作为 y 坐标。既然你想让它“相互叠加”,你需要模运算符%(检查help operators binary)。如果您的矩阵由一两条空行分隔,可能会更容易一些。

代码:

### animated matrix data
reset session

### create some random data
set print $Data
    do for [n=1:20] {
        do for [y=1:15] {
            Line = ''
            do for [x=1:15] {
                Line=Line.sprintf("% 3g",int(rand(0)*2)*2-1)
            }
            print Line
        }
    }
set print

set terminal gif animate delay 30
set output "tbMatrixAnimated.gif"
unset key 
N=15

do for [i=1:20] {
    plot $Data u 1:(int($2)%N):3 matrix every :::N*(i-1)::N*i-1 with image 
}
set output
### end of code

结果:(只有 20 个矩阵)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-11
    • 1970-01-01
    相关资源
    最近更新 更多