1

I have a datafile containing columns with different orders of magnitude. I would like to plot all columns with similar order of magnitude collectively into the same canvas. I do so by testing the maximum of each column using the stats command.

I tried so far

set key autotitle columnheader
set terminal pdfcairo
set out 'test.pdf'

do for [col=5:125]  {
  stats 'datafile' using col nooutput
  if( STATS_max < 1e-7 ) { 
    #draw to canvas 1
    plot 'datafile' using 1:col with lines
  } else {
    if( STATS_max < 1e-6 ) {
      #draw to canvas 2
      plot 'datafile' using 1:col with lines
    } else {
      #draw to canvas 3
      plot 'datafile' using 1:col with lines
    }
  }
}

but couldn't solve yet the problem to switch between the canvas.

The file looks like (1st row are the titles):

time   5.000/5.000   5.000/4.000    ...
1e-5   7.6e-23       3.057e-17      ...
0.002  3.4e-17       5.2e-13        ...
.      .             .          .
.      .             .             .
.      .             .                .

Is there a way to achieve this behaviour, and if yes, how? Thanks in advance.

1 Answer 1

0

You could first assemble corresponding column numbers into separate variables and then plot everything at the very end of the script. For example, with test.dat as:

1   10  11  100 101 1000    1001
2   20  21  200 201 2000    2001
3   30  31  300 301 3000    3001
4   40  41  400 401 4000    4001
5   50  51  500 501 5000    5001

the script below plots only the "first group", i.e., columns 2 and 3:

fName = 'test.dat'

set terminal pngcairo
set out 'fig.png'

#max. column number in the datafile
N = 5

#inspired by https://stackoverflow.com/a/35729052/5351549
_group_1 = ""
_group_2 = ""
_group_3 = ""

groupAppend(idx, col) = sprintf("_group_%d = _group_%d . \" %d\";", idx, idx, col)

do for [col=2:N]  {
    stats fName using col nooutput
    if( STATS_max < 1e2 ) { 
        eval groupAppend(1, col)
    } else {
        if( STATS_max < 1e3 ) {
            eval groupAppend(2, col)
        } else {
            eval groupAppend(3, col)
        }
    }
}

plot for [i in _group_1] fName u 1:int(i) w l t sprintf("column %s", i)

With newer versions of Gnuplot, one could then use arrays to hold the column indices instead of this indirect approach of storing them in a space-delimited fashion as a string.

Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.