1

I have a gnuplot file plot.gp whose contents are:

set terminal epslatex
set output 'data_plot.tex'
set multiplot

stats "data_file_1.dat" u 4 name "A"
stats "data_file_2.dat" u 4 name "B"

plot 'data_file_1.dat' u ($1<A_pos_max_y ? $1+10-A_pos_max_y : $1-A_pos_max_y):4 w p lt rgb "red",
'data_file_2.dat' u ($1<A_pos_max_y ? $1+10-A_pos_max_y : $1-A_pos_max_y):4 w p lt rgb "green"

data_file_1.dat and data_file_2.dat are both data files with 10 rows and 5 columns. The contents are (respectively):

#1  2   3   4   5
1   1   1   2   1
2   1   1   4   1
3   1   1   6   1
4   1   1   8   1
5   1   1   16  1
6   1   1   9   1
7   1   1   7   1
8   1   1   5   1
9   1   1   3   1
10  1   1   2   1

and

#1  2   3   4   5
1   1   1   5   1
2   1   1   7   1
3   1   1   12  1
4   1   1   18  1
5   1   1   9   1
6   1   1   5   1
7   1   1   7   1
8   1   1   3   1
9   1   1   2   1
10  1   1   1   1

I need the x coordinate (column 1) corresponding to maximum y value (from column 4). gnuplot displays an error message

undefined variable: A_pos_max_y

Is there some other way to fine the corresponding x coordinate for maximum y value?

Batfan
  • 77
  • 5
  • After the first `stats` command use a `show variables A_` to show all variables which were set from this call. You'll see, that the variable is called `A_index_max`. Note, that this index is zero-based, whereas your values in the first column start at one. How to generally get the matching x-value of the maximum, see http://stackoverflow.com/a/30132038/2604213. – Christoph Nov 29 '16 at 12:06
  • @Christoph Thank you so much! This worked. – Batfan Nov 29 '16 at 12:40
  • @Christoph Because I am shifting my x axis, the y points on the two ends are joined by a long line, like this - http://imgur.com/a/bvIR7 Is there a way to tell gnuplot to break this line? – Batfan Nov 29 '16 at 14:15
  • You must draw the two line parts separately. If you have problems with this, please ask a new question. It is difficult to explain this in a comment – Christoph Nov 29 '16 at 19:28

0 Answers0