Search code examples
gnuplotheatmapgif

gnuplot: animated heatmap is not created properly


My data is formatted this way (x, y, t, e):

enter image description here

I can't get an animated heatmap (in the gif format out of it). Here is my code:

set view map scale 1
set size square
set xlabel("x (m)")
set ylabel("y (m)")
set zlabel("V/m")
set title "E_z evolution"
set cblabel "E (V/m)"

set xrange [0:200]
set yrange [0:200]
set zrange [0:200]

set pm3d implicit at s 
set pm3d corners2color max 

set term gif animate delay 100 

set output "electric_field_evo.gif"
DATA = "result.dat"
stats DATA using 4

do for [i=1:int(STATS_blocks)]{
    splot DATA index (i-1) every 1::1::1 using (t=$3):(NaN):(NaN) notitle, \
          DATA index (i-1) using 1:2:4 with pm3d title sprintf("time = %g",t)
}

# do for [i=1:int(STATS_blocks)]{
#     splot DATA index (i-1) using 1:2:(t=$3,$4) with pm3d title sprintf("time = %g",t)
# 
# }

And the result (sample from the gif for t = 190, but the whole gif looks like that: empty heatmap), notice heatmap is empty, and legend limit on the right keep changing frame after frame (they should be set to overall min/max):

enter image description here

Result from the stats call:

enter image description here

EDIT: ADD SAMPLE DATA

       1             1            10    0.0000000E+00
       1             2            10    0.0000000E+00
       1             3            10    0.0000000E+00
       1             4            10    0.0000000E+00
       1             5            10    0.0000000E+00
       1             6            10    0.0000000E+00
       1             7            10    0.0000000E+00
       1             8            10    0.0000000E+00
       1             9            10    0.0000000E+00
       1            10            10    0.0000000E+00
       2             1            10    0.0000000E+00
       2             2            10   -2.4976539E-06
       2             3            10   -5.3808012E-04
       2             4            10   -2.6733600E-02
       2             5            10     1.610434    
       2             6            10   -2.6733600E-02
       2             7            10   -5.3808012E-04
       2             8            10   -2.4976580E-06
       2             9            10   -4.8060720E-09
       2            10            10    0.0000000E+00
       3             1            10    0.0000000E+00
       3             2            10   -4.0286686E-06
       3             3            10   -8.8682520E-04
       3             4            10   -6.8456993E-02
       3             5            10    0.8074945    
       3             6            10   -6.8456993E-02
       3             7            10   -8.8682520E-04
       3             8            10   -4.0286805E-06
       3             9            10   -9.2283745E-09
       3            10            10    0.0000000E+00
       4             1            10    0.0000000E+00
       4             2            10   -5.1066436E-06
       4             3            10   -1.0590287E-03
       4             4            10   -8.2134798E-02
       4             5            10    2.1518860E-02
       4             6            10   -8.2134798E-02
       4             7            10   -1.0590287E-03
       4             8            10   -5.1066618E-06
       4             9            10   -1.2548365E-08
       4            10            10    0.0000000E+00
       5             1            10    0.0000000E+00
       5             2            10   -5.3812091E-06
       5             3            10   -1.0855671E-03
       5             4            10   -8.8276833E-02
       5             5            10   -0.3647908    
       5             6            10   -8.8276833E-02
       5             7            10   -1.0855671E-03
       5             8            10   -5.3812300E-06
       5             9            10   -1.4017410E-08
       5            10            10    0.0000000E+00
       6             1            10    0.0000000E+00
       6             2            10   -5.1066436E-06
       6             3            10   -1.0618623E-03
       6             4            10   -8.5113689E-02
       6             5            10   -0.6305632    
       6             6            10   -8.5113689E-02
       6             7            10   -1.0618623E-03
       6             8            10   -5.1066618E-06
       6             9            10   -1.2548365E-08
       6            10            10    0.0000000E+00
       7             1            10    0.0000000E+00
       7             2            10   -4.0534715E-06
       7             3            10   -9.2593604E-04
       7             4            10   -8.5873455E-02
       7             5            10    -1.141478    
       7             6            10   -8.5873455E-02
       7             7            10   -9.2593604E-04
       7             8            10   -4.0534824E-06
       7             9            10   -9.2283745E-09
       7            10            10    0.0000000E+00
       8             1            10    0.0000000E+00
       8             2            10   -2.7910814E-06
       8             3            10   -7.3620438E-04
       8             4            10   -7.2833136E-02
       8             5            10   -0.6117640    
       8             6            10   -7.2833136E-02
       8             7            10   -7.3620438E-04
       8             8            10   -2.7910855E-06
       8             9            10   -4.9456297E-09
       8            10            10    0.0000000E+00
       9             1            10    0.0000000E+00
       9             2            10   -1.2563974E-06
       9             3            10   -4.6025845E-04
       9             4            10   -5.4116480E-02
       9             5            10    0.2660810    
       9             6            10   -5.4116480E-02
       9             7            10   -4.6025845E-04
       9             8            10   -1.2563978E-06
       9             9            10   -1.3758922E-09
       9            10            10    0.0000000E+00
      10             1            10    0.0000000E+00
      10             2            10    0.0000000E+00
      10             3            10    0.0000000E+00
      10             4            10    0.0000000E+00
      10             5            10    0.0000000E+00
      10             6            10    0.0000000E+00
      10             7            10    0.0000000E+00
      10             8            10    0.0000000E+00
      10             9            10    0.0000000E+00
      10            10            10    0.0000000E+00


       1             1            20    0.0000000E+00
       1             2            20    0.0000000E+00
       1             3            20    0.0000000E+00
       1             4            20    0.0000000E+00
       1             5            20    0.0000000E+00
       1             6            20    0.0000000E+00
       1             7            20    0.0000000E+00
       1             8            20    0.0000000E+00
       1             9            20    0.0000000E+00
       1            10            20    0.0000000E+00
       2             1            20    0.0000000E+00
       2             2            20   -6.1337640E-05
       2             3            20   -1.4902533E-03
       2             4            20    3.2542488E-03
       2             5            20    0.3296941    
       2             6            20    3.2542488E-03
       2             7            20   -1.4902533E-03
       2             8            20   -6.1346022E-05
       2             9            20   -9.6680935E-07
       2            10            20    0.0000000E+00
       3             1            20    0.0000000E+00
       3             2            20   -1.1673706E-04
       3             3            20   -2.5404668E-03
       3             4            20    4.2203847E-02
       3             5            20     1.418503    
       3             6            20    4.2203847E-02
       3             7            20   -2.5404671E-03
       3             8            20   -1.1675285E-04
       3             9            20   -1.8424856E-06
       3            10            20    0.0000000E+00
       4             1            20    0.0000000E+00
       4             2            20   -1.5823430E-04
       4             3            20   -2.6485780E-03
       4             4            20    9.9604763E-02
       4             5            20     1.320845    
       4             6            20    9.9604763E-02
       4             7            20   -2.6485780E-03
       4             8            20   -1.5825577E-04
       4             9            20   -2.5378417E-06
       4            10            20    0.0000000E+00
       5             1            20    0.0000000E+00
       5             2            20   -1.7999914E-04
       5             3            20   -2.5499274E-03
       5             4            20    0.1251577    
       5             5            20     2.412011    
       5             6            20    0.1251577    
       5             7            20   -2.5499277E-03
       5             8            20   -1.8002378E-04
       5             9            20   -2.9330913E-06
       5            10            20    0.0000000E+00
       6             1            20    0.0000000E+00
       6             2            20   -1.7958798E-04
       6             3            20   -2.3236359E-03
       6             4            20    0.1080537    
       6             5            20    0.6282932    
       6             6            20    0.1080537    
       6             7            20   -2.3236363E-03
       6             8            20   -1.7961276E-04
       6             9            20   -2.9684843E-06
       6            10            20    0.0000000E+00
       7             1            20    0.0000000E+00
       7             2            20   -1.6216180E-04
       7             3            20   -2.0380928E-03
       7             4            20    0.1280525    
       7             5            20   -0.2143435    
       7             6            20    0.1280525    
       7             7            20   -2.0380928E-03
       7             8            20   -1.6218355E-04
       7             9            20   -2.6321391E-06
       7            10            20    0.0000000E+00
       8             1            20    0.0000000E+00
       8             2            20   -1.2343809E-04
       8             3            20   -1.6553155E-03
       8             4            20    0.1108039    
       8             5            20   -0.6842759    
       8             6            20    0.1108039    
       8             7            20   -1.6553155E-03
       8             8            20   -1.2345419E-04
       8             9            20   -1.9603046E-06
       8            10            20    0.0000000E+00
       9             1            20    0.0000000E+00
       9             2            20   -6.7093235E-05
       9             3            20   -1.1316845E-03
       9             4            20    6.1340898E-02
       9             5            20    0.1410470    
       9             6            20    6.1340898E-02
       9             7            20   -1.1316845E-03
       9             8            20   -6.7101741E-05
       9             9            20   -1.0376655E-06
       9            10            20    0.0000000E+00
      10             1            20    0.0000000E+00
      10             2            20    0.0000000E+00
      10             3            20    0.0000000E+00
      10             4            20    0.0000000E+00
      10             5            20    0.0000000E+00
      10             6            20    0.0000000E+00
      10             7            20    0.0000000E+00
      10             8            20    0.0000000E+00
      10             9            20    0.0000000E+00
      10            10            20    0.0000000E+00

Solution

  • As mentioned in the comments, gnuplot expects a certain data structure for splot ... with pm3d. See the following minimized example. If you can change your data in that way it would be the easiest. Otherwise, if you cannot or don't want to change your original datafiles you can think about some workaround and insert the empty line with gnuplot.

    Required data format:

      1   1   1.1   # 1st block start, index=0
      1   2   1.2
      1   3   1.3   # one blank line follows
    
      2   1   1.4
      2   2   1.5
      2   3   1.6   # one blank line follows
    
      3   1   1.7
      3   2   1.8
      3   3   1.9   # 1st block end, followed by two blank lines
    
    
      1   1   2.1   # 2nd block start, index=1
      1   2   2.2
      1   3   2.3   # one blank line follows
    
      2   1   2.4
      2   2   2.5
      2   3   2.6   # one blank line follows
    
      3   1   2.7
      3   2   2.8
      3   3   2.9