gnuplot 使用矩阵和图像创建热图动画

问题描述 投票:0回答:1

我尝试创建热图动画 我必须使用以下方法得到最终结果: 矩阵和“带图像” 但我想逐点创建动画。 我设法逐列完成,但不能逐点完成

这是我的mwe


$Data <<EOD
2 1 9 3 9 4 4 9 1 4 1 
9 0 4 9 0 4 2 3 6 7 1 
1 8 5 5 2 1 5 4 1 5 9 
7 3 5 8 4 7 3 6 4 7 0 
9 0 6 5 5 9 0 5 0 0 2 
2 6 3 2 1 1 4 0 3 5 7 
9 2 6 8 9 2 2 5 1 5 2 
3 2 4 9 6 0 0 1 9 3 8 
6 7 1 9 1 0 8 9 1 7 6 
2 7 3 0 3 6 8 5 5 1 4 
9 0 2 6 4 6 9 4 5 0 8
EOD

stats $Data nooutput   # get the number of rows
lin = STATS_records
col = STATS_columns

nb_p = lin * col

print "lin: " . lin
print "col: " . col
print "nb_p: " . nb_p

do for [cur = 0 : nb_p] {
    plot $Data matrix using 1:2:3 every ::::cur with image title "n: ".cur
    pause 1
}

我也尝试过:

do for [c = 0 : col] {
    do for [l = 0 : lin] {
    plot $Data using c:l with points pt 5 title 'c: '.c.' l: '.l
    pause 1
    }
}

animation matrix gnuplot heatmap
1个回答
0
投票

如果我正确理解你的问题,我的第一个想法是:

  • 通过

    stats $Data matrix noouput

    分析你的矩阵
  • STATS_records
    将包含点数

  • STATS_blank+1
    将代表行数

  • 将 cbrange 设置为固定范围

    [STATS_min:STATS_max]

  • 使用过滤器仅根据

    n

    绘制所需的数据点

脚本:

### plot animated matrix point by point
reset session

$Data <<EOD
2 1 9 3 9 4 4 9 1 4 1 
9 0 4 9 0 4 2 3 6 7 1 
1 8 5 5 2 1 5 4 1 5 9 
7 3 5 8 4 7 3 6 4 7 0 
9 0 6 5 5 9 0 5 0 0 2 
2 6 3 2 1 1 4 0 3 5 7 
9 2 6 8 9 2 2 5 1 5 2 
3 2 4 9 6 0 0 1 9 3 8 
6 7 1 9 1 0 8 9 1 7 6 
2 7 3 0 3 6 8 5 5 1 4 
9 0 2 6 4 6 9 4 5 0 8
EOD

stats $Data matrix nooutput   # get size and min/max of matrix
N    = STATS_records
rows = STATS_blank+1
cols = N/rows
cmin = STATS_min
cmax = STATS_max

set size ratio -1
set xrange [-0.5:cols-0.5] noextend
set yrange [-0.5:rows-0.5] reverse noextend
set tics out
set palette rgb 33,13,10
set key at screen 0.20,0.95
set cbrange[cmin:cmax]

set term gif size 640,384 animate delay 5
set output "SO79003207.gif"

myFilter(n) = ($2*rows + $1) <= n ? $3 : NaN

do for [n = 0 : N-1] {
    plot $Data matrix using 1:2:(myFilter(n)) w image ti "n = ".n
}
set output
### end of script

结果:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.