graph - 用于平均多个文件的 Gnuplot 脚本

标签 graph visualization gnuplot

我在几个文件中有一系列测量。每个文件看起来像这样:

1 151.973938 144.745789 152.21991 17:57:14
2 151.995697 144.755737 152.21991 17:57:14
3 152.015747 144.765076 152.21991 17:57:14
.
.
.

我正在寻找一种可能性来计算多个文件中相同字段的平均值。在过程结束时,我想要一个平均测量值的图表。

gnuplot 可以实现吗?我自己无法在 gnuplot 中找到合适的选项。如果没有,您会推荐哪种不同的方式来实现这一目标?

最好的问候,朱罗

最佳答案

您无法在 gnuplot 中完成所有操作。 Gnuplot 仅限于一次处理一个文件中的列。您需要一些其他实用程序来预处理您的数据。假设数据采用您演示的格式(使用空格而不是分号),此脚本将取第二、第三和第四列的平均值,并吐出一个文件,其中第一和第五列相同,中间取平均值。在只有 .txt 的目录中运行这个 bash 脚本要处理的文件。

#!/bin/bash

sum=$(ls -l *.txt | wc -l)
paste -d" " *.txt | nawk -v s="$sum" '{
    for(i=0;i<=s-1;i++)
    {
        t1 = 2+(i*5)
        temp1 = temp1 + $t1
        t2 = 3+(i*5)
        temp2 = temp2 + $t2
        t3 = 4+(i*5)
        temp3 = temp3 + $t3
    }
    print $1" "temp1/s" "temp2/s" "temp3/s" "$5
    temp1=0
    temp2=0
    temp3=0
}'

从 gnuplot 内部,您可以像这样运行脚本:
!myscript.sh > output.out
plot 'output.out' u 1:2 # orwhatever

或者像这样:
plot '<myscript.sh' u 1:2

(代码灵感来自我发现的 here 。)

关于graph - 用于平均多个文件的 Gnuplot 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10818012/

相关文章:

Javascript图形布局算法

python - 使用神经网络的骑士之旅

algorithm - 测试网格通过性

python - python中节点图的ASCII可视化

binary-search-tree - 如何从 C++ 为 Graphviz 生成二叉树点文件

python - 在 Altair 中控制箱宽度

string - gnuplot - 使用字符串变量

algorithm - 与 n 个其他顶点距离最短的顶点

gnuplot - 根据多个数据 block 的列值改变点颜色 gnuplot

python - 如何制作基于文本的界面(TUI/TLI)来监控 OpenFOAM 求解器日志文件?