Gnuplot:制作由矩阵生成的地图的gif? [英] Gnuplot: Making a gif of a map generated with matrix?

查看:83
本文介绍了Gnuplot:制作由矩阵生成的地图的gif?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

 用图像绘制'firstmatrix.dat'矩阵 

I generated a .dat file with 100 matrix 15x15, now I want to create a gif which shows the evolution from the first to the last matrix. They are all matrix with 1 or -1, so if I want to represent the inicial matrix I can copy and paste it in another file and I put this in gnuplot:

plot 'firstmatrix.dat' matrix with image

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

To create the gif I'm trying to do this in 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
}

I intend to read from the first line of the file to the 15th line, then from the 16th to the 30th and so on.

I put only 5 frames to see better the result, and I obtain that the gif shows the first matrix in the first frame and nothing more, only white frames.

The error message is four times this one:

warning: Skipping data file with no valid points

So the data for the first frame, the first matrix, is well processed but not the rest. So here is my problem, I don't know why it process good the first one and no more.

Thanks in advance.

It shows only the first matrix in the first frame

解决方案

You've been pretty close. But it took me also some iterations and testing... Apparently, slicing a block of rows from a matrix requires every :::rowFirst::rowLast (mind the 3 colons at the beginning). And then gnuplot apparently takes the row index of the whole matrix as y-coordinate. Since you want to have it "on top of each other" you need the modulo operator % (check help operators binary). It might have been a bit easier if your matrices were separated by one or two empty lines.

Code:

### 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

Result: (only 20 matrices)

这篇关于Gnuplot:制作由矩阵生成的地图的gif?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆