Search code examples
statisticsgnuplot

gnuplot for which x the y is maximum


In Gnuplot, I want to obtain from stats the value of x where the y attains maximum. The solution here uses a very clever trick. This solution only works without setting xrange. If I have a spike in data at the begining which i want to avoid, I want to set xrange [200:1000] and then do stats data using 1:3 nooutput will produce STATS_index_max_y for which the first value above 200 has index 0. When this is used in every the value of the x is incorrect.

Is there an easy "gnuplot" only way to get around this?


Solution

  • I don't know why the accepted answer to your linked question does is so complicated.

    If you want to find ymax and the corresponding x-value simply do:

    stats [200:1000] "myFile.dat" u 1:3 nooutput
    print STATS_pos_max_y, STATS_max_y
    

    After having carried out a stats command, type show var STATS in the console and you will see all the variables which have been calculated.