gnuplot 计算多列统计数据

gnuplot computing stats over multiple columns

我有一个简单的 9 列文件。我不想为每一列计算某些统计数据然后绘制它(使用 gnuplot)。

1) 这就是我计算除第一列之外的每一列的统计信息的方式。

stats 'data' every ::2 name "stats"

2) 在输出屏幕中我可以看到操作成功。注意columns/records的个数是8

* FILE: 
  Records:      8
  Out of range: 0
  Invalid:      0
  Blank:        0
  Data Blocks:  1

* COLUMNS:
  Mean:          6.5000       491742.6625
  Std Dev:       2.2913          703.4865
  Sum:          52.0000       3.93394e+06
  Sum Sq.:     380.0000       1.93449e+12

  Minimum:       3.0000 [0]   490312.0000 [2]
  Maximum:      10.0000 [7]   492643.5000 [7]
  Quartile:      4.5000       491329.5000
  Median:        6.5000       491911.1500
  Quartile:      8.5000       492252.2500

  Linear Model: y = 121.8 x + 4.91e+05
  Correlation:  r = 0.3966
  Sum xy:       2.558e+07

3) 现在我可以通过像这样附加 _x 和 _y 来访问前两列的统计信息

print stats_median_x
print stats_median_y

我的问题是:

我知道我可以简单地添加一个 python 脚本来预先计算所有这些,但如果有一种使用 gnuplot 本身的简单方法来完成它,我宁愿避免它。

谢谢!

简答

  • "How can I access statistics of the other column?"
    使用 stats 'data'using n 您将访问第 nth 列...
  • "How can I plot for example all medians?"
    例如set printdo for 循环可以创建一个数据文件,您可以将其用于绘图。

可行的解决方案

    set print "StatDat.dat" 
    do for [i=2:9] { # Here you will use i for the column.
      stats  'data.dat' u i nooutput ; 
      print i, STATS_median, STATS_mean , STATS_stddev # ...
    } 
    set print
    plot "StatDat.dat" us 1:2 # or whatever column you want...

多说几句
向 gnuplot 本身求助 help stats 可以阅读很多有趣的东西 :-).

Syntax:
stats 'filename' [using N[:M]] [name 'prefix'] [[no]output]]
This command prepares a statistical summary of the data in one or two columns of a file. The using specifier is interpreted in the same way as for plot commands. See plot for details on the index, every, and using directives.

  • 从第一个高亮的句子我们可以了解到它每次准备一列或最多两列的统计信息(很遗憾,让我们以后再看......)。
  • 从第二个突出显示的句子可以看出它将遵循与 plot 命令相同的语法:
    所以 stats 'data'using 3 会给你 x
    中第 3 列的统计数据 以及 x,y 中第 4 和第 5 的 stats 'data' using 4:5...

关于您的解释的注释

  1. 你说

    This is how I compute statistics for every column excluding the first one.
    stats 'data' every ::2 name "stats"

    这实际上不是前两列的统计数据不包括前两行,实际上它们的计数器是从 0 而不是 1 开始的。

  2. 作为上述assumption/interpretation的结果,当我们阅读

    Records: 8

    表示计算的行数为8;您的文件有 10 (usable) 行,您指定 every ::2 并跳过前两行,因此您有 8 条对统计有用的记录。
    确实如此,我们可以更好地理解 help stats 中所说的

    STATS_records           # total number of in-range data records
    

    暗示"used to compute this statistic".

在 gnuplot 4.6 补丁级别 4 上测试
正在处理 gnuplot 版本 5.0 补丁级别 1