【问题标题】:Doing calculations in gnuplot's plot command在 gnuplot 的 plot 命令中进行计算
【发布时间】:2013-02-20 10:49:37
【问题描述】:

以下 gnuplot 代码运行良好:

plot 'data.txt'  using 2:4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;

在下面的代码中,我想说:“使用第 4 列中的数字,然后除以第 3 列中的数字”。或者:“使用第 2 列中的数字,但除以常数 2.0”。以下代码演示了我尝试实现的目标,但它不起作用。

plot 'data.txt'  using 2:4/4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;
plot 'data.txt'  using 2:4/2.0  '   %lf %lf %lf %lf' title "1 PE" with linespoints;

这样的事情可能吗?

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    我通常不使用这种格式的数据文件,但我认为您正在寻找类似的东西:

    #divide column 4 by column 3
    plot 'data.txt'  using 2:($4/$3)  '   %lf %lf %lf %lf' title "1 PE" with linespoints
    
    #divide column 4 by constant 10.0
    plot 'data.txt'  using 2:($4/10.0)  '   %lf %lf %lf %lf' title "1 PE" with linespoints
    

    作为旁注,我认为没有任何理由将格式部分传递给在此处使用。 Gnuplot 在空白处拆分数据文件就好了:

    plot 'data.txt'  using 2:($4/$3) title "1 PE" with linespoints
    

    应该可以正常工作。

    【讨论】:

    • 非常感谢,这行得通。另外,是的,格式字符串不是必需的,酷!
    • 如何将文件 1 中的列除以文件 2 中的列?
    • @Ruzayqat -- 我已经有一段时间没有在 Gnuplot 工作了,但是在过去,没有办法做到这一点。您需要某种工具来将列压缩在一起,然后您可以通过管道输入数据。
    【解决方案2】:

    只是为了补充给定的答案,如果您更喜欢使用列名(当您的数据有标题时),那么可以使用以下语法:

    plot 'data.dat' using 'header1':(column('header2')*column('header3')) with lines
    

    编辑

    我的回答收到了一些反对票,但我不知道为什么。虽然我可以很容易地找到如何使用数字列引用进行计算,但在文档或 SO 中几乎不可能找到使用命名列的技巧,所以我仍然希望我的回答可以帮助其他人。

    【讨论】:

    • 这实际上是一个非常有帮助的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 1970-01-01
    • 1970-01-01
    • 2011-10-31
    • 1970-01-01
    • 2011-10-31
    • 1970-01-01
    相关资源
    最近更新 更多