Gnuplot:在绘图画布之间切换

骆驼香烟盒

我有一个包含不同数量级列的数据文件。我想将所有具有相似数量级的列一起绘制到同一个画布中。我通过使用stats命令测试每列的最大值来做到这一点

我试过到目前为止

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
    }
  }
}

但还不能解决在画布之间切换的问题。

该文件看起来像(第一行是标题):

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        ...
.      .             .          .
.      .             .             .
.      .             .                .

有没有办法实现这种行为,如果是,如何实现?提前致谢。

可能

您可以首先将相应的列号组合成单独的变量,然后在脚本的最后绘制所有内容。例如,test.dat作为:

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

下面的脚本仅绘制“第一组”,即第 2 和第 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)

使用较新版本的 Gnuplot,人们可以使用数组来保存列索引,而不是这种以空格分隔的方式将它们存储为字符串的间接方法。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章