Search code examples
matrixgnuplot

Gnuplot - Unable to properly plot two matrices with different sizes


My data file is as follows:

#smaller matrix
5   0.00    0.25    0.50    0.75    1.00
0.00    1   2   3   4   5
0.25    5   4   3   2   1
0.50    1   2   3   4   5
0.75    5   4   3   2   1
1.00    1   2   3   4   5


#bigger matrix
8   0.00    0.25    0.50    0.75    1.00    1.25    1.50    1.75
0.00     1  2   3   4   5   6   7   8
0.25    5   4   3   2   1   0   1   2
0.50    1   2   3   4   5   6   7   8
0.75    5   4   3   2   1   0   1   2
1.00    1   2   3   4   5   6   7   8
1.25    5   4   3   2   1   0   1   2
1.50    1   2   3   4   5   6   7   8
1.75    5   4   3   2   1   0   1   2

The gnuplot script is as follows:

set term png size 900, 400
set output 'matrices-test.png'
set multiplot layout 1,2

set xrange [0:1.0]
set yrange [0:1.0]
plot 'matrices-test' index 0 nonuniform matrix w image

set xrange [0:1.75]
set yrange [0:1.75]
plot 'matrices-test' index 1 nonuniform matrix w image

unset multiplot

When I run this script, the smaller matrix comes out distorted. The image is tilted and the data seems mangled:

enter image description here

If I put each matrix into a separate file, they are both plotted without problems.

Am I doing something wrong? Or is this a bug in gnuplot? (I'm using 5.4.1, the newest version, in Ubuntu Linux.)


Solution

  • You have hit a program bug. Your script works correctly in the development version (gnuplot 5.5) and the fix will be included in the next 5.4 stable release.

    Work-around:

    The bug has something to do with there being multiple data blocks in the input file. It is not triggered if the matrices are in separate files or if they are loaded into separate data blocks and plotted from there. So one work-around would be to select out the first data block externally:

    unset key
    set auto noextend
    
    set multiplot layout 1,2
    
    plot '<head --lines=7 matrices.dat' index 0 nonuniform matrix w image
    plot 'matrices.dat' index 1 nonuniform matrix w image
    
    unset multiplot
    

    enter image description here