Reputation: 325
I'm trying to plot a csv file which is like this:
a 531049
b 122198
c 3411487
d 72420
e 1641
f 2181578
. .
. .
. .
but these values should be scaled using another csv file which is in the same format.
i.e other file
a 45
b 12...
I want to plot 531049/45 and so on. first column will be the x axis and the second is the y-axis
how can I do this without merging 2 files?
Upvotes: 0
Views: 575
Reputation: 309831
Gnuplot's using is meant to read data from a single file/stream so you need to merge the two files somehow. I would use python
for this since it is my go-to tool for just about everything. I would write a script which reads from the 2 files and writes the data to standard output. Something like:
#merge.py
import sys
file1,scale_factor_file = sys.argv[1:]
#Read the scale factors into a dictionary
d = {}
with open(scale_factor_file) as sf:
for line in sf:
key,scale_factor = line.split()
d[key] = float(scale_factor)
#Now open the other file, scaling as we go:
with open(file1) as fin:
for line in fin:
key,value = line.split()
print key,float(value)/d.get(key,1.0)
Now you can use gnuplot's ability to read from pipes to plot your data:
plot '< python merge.py datafile file_with_scale_factors' using 2
Upvotes: 1