gnuplot: How to Correlate Points on two graphs
A quick question about a gnuplot. I have two graphs, ploted f开发者_开发知识库rom file, like this:
plot "t2" using 1:75 with linespoints title "crop 20",\
"t2" using 1:11 with linespoints title "crop 30"
Now I want to identify points on both graphs if they have identical height e.g Y coordinate. It could be a different colour, or a perfect solution would be to draw a line between them.
Any ideas? Thanks a lot.
EDIT
Thanks for the reply Sunhwan Jo, method suggested works fine, as long as similar values appear in the same order. See the image
Two graphs share several more points in the same height, but its not picked up due to length difference.
You may use external program to filter out data points that have same data in two different column (here I've examined if 75th and 11th column has same entry).
plot "t2" using 1:75 with linespoints title "crop 20",\
"t2" using 1:11 with linespoints title "crop 30",\
"< awk '{if ($75==$11) print $0}' t2" us 1:11 with lines points title "crop 20/30"
EDIT:
Okay, above will not work if you would like to show the data points that have same data in different rows. AWK script will be more elaborated. I have tried as below, hope this helps.
Here's test data.
0 0.0 0.0
1 0.3 0.6
2 1.6 1.6
3 0.3 1.5
4 0.6 3.6
5 0.3 4.3
6 0.3 0.7
7 5.5 5.5
8 6.6 6.6
9 5.2 5.2
10 8.3 8.3
11 2.7 5.0
12 2.8 8.3
13 3.3 2.8
14 7.9 3.9
15 9.9 7.9
16 15.3 15.3
17 14.7 14.7
18 3.8 18.1
19 18.1 12.1
And the gnuplot command (note some obvious difference in column designation):
plot 'test.dat' us 1:2 w lp title "1", \
'test.dat" us 1:3 w lp title "2", \
"< awk '{ind[NR]=$1; arr1[NR]=$2; arr2[NR]=$3} END{for (i=1; i<=NR; i++) {for (j=1; j<=NR; j++) {if (arr1[i]==arr2[j]) print ind[i], arr1[i]}}}' test.dat' test.dat" us 1:2 w lp title '1==2'
Resulting plot:
The previous answer using a awk script to preprocess the data is a good method. Here I give a method using only gnuplot. There is a ternary operator--"?:". Uisng this operator you can pick the points with same value out. For example, "plot 'data.dat' u 1:($11==$75?$11:1/0) w p lc rgb'blue'" will plot only the points with $11==$75. I have written the details in my blog. If any question, visit http://gnuplot-surprising.blogspot.com/2011/09/manipulate-data-using-ternary-operator.html.
精彩评论