Search code examples
gnuplot

Gnuplot: plot specific matrix from file with many matrices


I have a file, let's say 6 x 2 which contains the data of three 2 by 2 matrices:

1 2
3 2
1 5
6 2 
8 5 
2 7

Now I want to be able to plot specific matrices of that file. Like the matrix

1 5
6 2

For my other files where I have one dimensional data I use ::1::10 if I want to plot Data from the first ten lines.

Bit how can I do that for matrices?


Solution

  • This resembles your other question with the difference that you don't have a single column file but already several matrices, but "glued" together. If you had them separated by two empty lines, you could easily address the individual matrices via index (check help index).

    Nevertheless, you can address your data via every (check help matrix every).

    So, there is no need for external tools, you can simply do it with gnuplot only, hence platform-independently. The example below will split the data into four 2x3 matrices.

    Script: (works for gnuplot>=5.0.0, Jan. 2015)

    ### split data into several matrices
    reset session
    
    $Data <<EOD
     1   2   3
     4   5   6
     7   8   9
    10  11  12
    13  14  15
    16  17  18
    19  20  21
    22  23  24
    EOD
    
    m = 2
    n = 3
    set cbrange [0:25]
    set key noautotitle
    
    set multiplot layout 2,2
        do for [i=0:3] {
            set title sprintf("Matrix %d",i)
            plot $Data matrix u 1:2:3 every :::i*m::(i+1)*m-1 w image
        }
    unset multiplot
    ### end of script
    

    Result:

    enter image description here