Gnuplot:最多绘制两个文件 [英] Gnuplot: plotting the maximum of two files
问题描述
假设我有两个这样格式化的文件:
x --- y
0 --- 2
1-2.4
2 --- 3.6
y的值不同.
有没有一种方法可以绘制单个图,即对于每个x,两个文件之间的y的最大值?
邓诺(Dunno)不能很好地解释我的自我.
我正在尝试使用条件语句,但是找不到任何可让我搜索2个不同文件的表达式
仅使用gnuplot无法将两个或多个文件合并在一个图中.您必须使用外部工具来执行此操作,例如命令行实用程序paste
:
max(x, y) = (x > y ? x : y)
plot '< paste fileA.txt fileB.txt' using 1:(max($2, $4))
y
值包含在第二列和第四列中.
下一个版本使用python
脚本和numpy
来串联文件,但是其他任何脚本语言也可以:
"""paste.py: merge lines of two files."""
import numpy as np
import sys
if (len(sys.argv) < 3):
raise RuntimeError('Need two files')
A = np.loadtxt(sys.argv[1])
B = np.loadtxt(sys.argv[2])
np.savetxt(sys.stdout, np.c_[A, B], delimiter='\t')
要绘制,请使用:
max(x, y) = (x > y ? x : y)
plot '< python paste.py fileA.txt fileB.txt' using 1:(max($2, $4))
let's assume I have two files formatted like this:
x --- y
0 --- 2
1 --- 2.4
2 --- 3.6
which differ for the values of y.
is there a way to plot a single graph that is, for every x, the maximum value of y between the two files?
Dunno if explained my self sufficiently well.
I was trying with conditional sentences but I couldn't find any expression that let me search in 2 different files
There is no way to combine two files or more in a single plot with gnuplot only. You must use an external tool to do this, e.g. the command line utility paste
:
max(x, y) = (x > y ? x : y)
plot '< paste fileA.txt fileB.txt' using 1:(max($2, $4))
The y
values are contained in the second and fourth columns.
This next version uses a python
script with numpy
to concatenate the files, but any other scripting language would also do:
"""paste.py: merge lines of two files."""
import numpy as np
import sys
if (len(sys.argv) < 3):
raise RuntimeError('Need two files')
A = np.loadtxt(sys.argv[1])
B = np.loadtxt(sys.argv[2])
np.savetxt(sys.stdout, np.c_[A, B], delimiter='\t')
To plot, use:
max(x, y) = (x > y ? x : y)
plot '< python paste.py fileA.txt fileB.txt' using 1:(max($2, $4))
这篇关于Gnuplot:最多绘制两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!