在gnuplot的plot命令中进行计算

Joh*_*nes 9 gnuplot

以下gnuplot代码工作正常:

plot 'data.txt'  using 2:4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;
Run Code Online (Sandbox Code Playgroud)

在下面的代码中,我想说:"使用第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;
Run Code Online (Sandbox Code Playgroud)

这样的事情可能吗?

mgi*_*son 16

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

#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
Run Code Online (Sandbox Code Playgroud)

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

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

应该工作得很好.


Seb*_*aan 10

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

plot 'data.dat' using 'header1':(column('header2')*column('header3')) with lines
Run Code Online (Sandbox Code Playgroud)

编辑

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

  • 这实际上是一个非常有用的答案。 (2认同)