Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gnuplot plot difference of 2 columns

Tags:

plot

gnuplot

I have two files A and B. Both files contain 2 columns, x and y.

Now, I want to plot a graph for x vs (yA - yB). Does gnuplot provide a command for the same ?

One more thing, lets say xA and xB are not same. How should I plot a graph where x-axis contains all elements which are in both, xA and xB and y-axis is the difference is the corresponding y-components ?

like image 558
prathmesh.kallurkar Avatar asked Oct 26 '25 10:10

prathmesh.kallurkar


1 Answers

First, preprocess the files with join in bash:

join <(sort -k1,1 file1) <(sort -k1,1 file2) > file3

Sorting the files is essential, otherwise join would not work.

Then you can use the result to draw the graph:

plot '< sort -n file3' using 1:($2-$3) with lines

Again, numeric sorting is needed here, because join uses alphanumeric sorting which makes the lines cross each other.

like image 78
choroba Avatar answered Oct 29 '25 07:10

choroba



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!