Is it possible to plot a series of matrices in this format using gnuplot

Viewed 40

My code currently creates an output that comes out as so (using example numbers)

0.0 0.0 0.0 
0.0 1.0 0.0 
0.0 0.0 0.0 
0.0 0.0 2.0 

0.0 0.0 0.0 
0.0 0.0 2.0 
0.0 0.0 0.0 
1.0 0.0 0.0 


0.0 0.0 0.0 
0.0 3.0 0.0 
0.0 0.0 0.0 
0.0 0.0 1.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0

was hoping for a solution on how to plot this data either as a 3D splot or as a gif that cycles through each matrix (actual code contains a few hundred matrices). I'm able to alter the output format if necessary. So far I've tried

do for [i=1:7] {
plot "data.txt" matrix with image
}

As well as attempting other solutions I've found on the site but none seem to be trying to do the same thing as me.

If anyone who has gnuplot experience could help me that would be a huge help (I'm using mac if that makes a difference)

1 Answers

Welcome to StackOverflow! I assume all separations of your matrices are two empty lines. If this is the case you can address the matrices via index (check help index). You can find out with stats (check help stats) how many blocks you have. Loop through these blocks and set the output to term gif animate (check help gif). Instead of plotting the datablock $Data simply plot your file.

Scrupt:

### plot matrices as asnimation
reset session

$Data <<EOD
0.0 0.0 0.0 
0.0 1.0 0.0 
0.0 0.0 0.0 
0.0 0.0 2.0 


0.0 0.0 0.0 
0.0 0.0 2.0 
0.0 0.0 0.0 
1.0 0.0 0.0 


0.0 0.0 0.0 
0.0 3.0 0.0 
0.0 0.0 0.0 
0.0 0.0 1.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0 


3.0 0.0 0.0 
0.0 0.0 0.0 
1.0 0.0 2.0 
0.0 0.0 0.0 
EOD


stats $Data u 0 nooutput    # get the number of blocks
N = STATS_blocks

set term gif size 600,400 animate delay 30
set output "SO72250259.gif"

set size ratio -1
set cbrange [0:3]
set xrange [-0.5:2.5]
set yrange [-0.5:3.5]

do for [i=0:N-1] {
    plot $Data index i matrix w image
}
set output
### end of script

Result:

enter image description here

Related