Gnuplot: plotting the maximum of two files

时间秒杀一切 提交于 2019-12-18 07:09:47

问题


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


回答1:


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))


来源:https://stackoverflow.com/questions/19079146/gnuplot-plotting-the-maximum-of-two-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!