I have a set of data data.txt which can be fit to a Gaussian function, f(x). I want to determine the coordinates of the point of maxima (peak) from both the data given and also from the fit function f(x). How can I achieve this in gnuplot?


1 Answer 1


According with this blog the way to find max e min with gnuplot is:

With Gnuplot 4.6 the both the x and y coordinate of maximum and minimum points can be find out easily. The method is using new command "stats". This command is used for statistic. When it is run, some statistical results will be gotten. If your data file contains two column of data, (STATS_pos_max_y, STATS_max_y) will be the coordinate of the maximum point and (STATS_pos_min_y, STATS_min_y) will be the coordinate of the minimum point.

If you want to find maxima from the fit function $f(x)$ there are different way:

  • computational brutal make an array, with a suitable range, evaluate it with your $f(x)$ and find the max in the result array. With the same index you find also the $x$ coordinate. To find the max and minimun in the arrays you can use the stats command.
  • math essentially keep the analytic form of your function $f(x)$ and study max e min with derivative. Here depends how you build the function $f$. For example with gnuplot fit command use a nonlinear least-squares (NLLS) Marquardt-Levenberg algorithm and with the keyword via you can indicate the parameter are to be adjusted. If you define $f(x)$ as a Gaussian you will obtain the various parameters and you can study it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.