2
votes

I can never get both the loops and layout to work. My data looks like this

2   1   -93.50882606    -93.51697017    -93.51086209
2   2   -93.51324833    -93.51714636    -93.51422284
2   3   -93.52672325    -93.53627468    -93.52911111
2   4   -93.51306982    -93.52395431    -93.51579094
2   5   -93.50908482    -93.51902598    -93.51157011
2   6   -93.50825891    -93.51587124    -93.51016199
2   7   -93.50822884    -93.51691667    -93.51040080
3   1   -93.50792762    -93.51624138    -93.51000606
3   2   -93.51196983    -93.51499451    -93.51272600
3   3   -93.50793572    -93.51664664    -93.51011345
3   4   -93.50768256    -93.51618396    -93.50980791
3   5   -93.50771675    -93.51656535    -93.50992890
4   1   -93.50762338    -93.51564665    -93.50962919
4   2   -93.53234566    -93.54136850    -93.53460137

And i want plots with values from columns 2,3,4,5 untill the value of the first column changes. Then it should start a new multiplot underneath it.

The numbers in the first column are always different so i don't know how to make the loop without knowing how many there will be and not set multiplot layout on fixed amount

1

1 Answers

1
votes

This will most likely require some external processing of the input file. One approach could be as follows

reset
set terminal pngcairo enhanced
set output 'fig.png'

set xtics out nomirror

set ytics out nomirror
set ytics format '%.3f'

set xr [1:7]

set key bottom right

#find the number of unique (consecutive) values from the first column
N = system("gawk '{print $1}' input.dat | uniq | wc -l")

#adjust multiplot setup
set multiplot layout N, 1

do for [i=1:N] {
    #find the corresponding group identifier
    idx = system(sprintf("gawk '{print $1}' input.dat | uniq | head -n%d | tail -n1", i))

    set title sprintf("group %s", idx)

    plotCmd=sprintf("<gawk 'BEGIN{p=v=0;} {if(!p||$1!=v){v=$1;p+=1} if(p==%d){print p,$2,$3,$4,$5} if(p>%d){exit;}}' input.dat", i, i)
    plot \
        plotCmd u 2:3 w l lc rgb 'black' t 'column 3', \
        '' u 2:4 w l lc rgb 'dark-red' t 'column 4', \
        '' u 2:5 w l lc rgb 'royalblue' t 'column 5'
}

The strategy is to:

  1. invoke gawk and uniq in order to determine the number of unique (consecutive) ids which appear in the first column of the input file (assumed to be named input.dat)
  2. create corresponding multiplot layout
  3. iterate over all groups and for each group, plot the corresponding chunk of data. To this end, the script above invokes gawk again to filter the corresponding rows (it just keeps track of the group number of the value in the first column, prints all rows for a particular group of interest and finally terminates once the entire group has been loaded)

This then produces: enter image description here