I have 2 dat files:
a.dat
#Xs
100 25
200 56
300 75
400 67
b.dat
#Xs
100 65
200 89
300 102
400 167
I want to draw a graph in the gnuplot where the yy values are a ratio between the values of a.dat and b.dat respectively. e.g., 25/65, 56/89, 75/102, and 67/167.
How I do this? I only know make a plot like this, and not with the ratio.
plot "a.dat" using 1:2 with linespoints notitle
"b.dat" using 1:2 with linespoints notitle
To plot functions simply type: plot [function] at the gnuplot> prompt. Discrete data contained in a file can be displayed by specifying the name of the data file (enclosed in quotes) on the plot or splot command line. Data files should have the data arranged in columns of numbers.
5.9 Does gnuplot support multiple y-axes on a single plot? Yes. 2D plots can have separate x axes at the bottom (x1) and top (x2), and separate y axes at the left (y1) and right (y2).
Running gnuplot is easy: from a command prompt on any system, type gnuplot. It is even possible to do this over a telnet or ssh connection, and preview the graphs in text mode!
Gnuplot can read binary data files. However, adequate information about details of the file format must be given on the command line or extracted from the file itself for a supported binary filetype. In particular, there are two structures for binary files, a matrix binary format and a general binary format.
You cannot combine the data from two different files in a single using
statement. You must combine the two files with an external tool.
The easiest way is to use paste
:
plot '< paste a.dat b.dat' using 1:($2/$4) with linespoints
For a platform-independent solution you could use e.g. the following python script, which in this case does the same:
"""paste.py: merge lines of two files."""
import sys
if (len(sys.argv) < 3):
raise RuntimeError('Need two files')
with open(sys.argv[1]) as f1:
with open(sys.argv[2]) as f2:
for line in zip(f1, f2):
print line[0].strip()+' '+line[1],
And then call
plot '< python paste.py a.dat b.dat' using 1:($2/$4) w lp
(see also Gnuplot: plotting the maximum of two files)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With