Saturday, May 19, 2012

How to pick out the maximum and minimum points when plotting with gnuplot?

Picking out the maximum and minimum points from a data file may be useful when you want to make some explanation to your graph. It is known that GPVAL_Y_MAX (GPVAL_Y_MIN) is the maximum (minimum) value. But what is the corresponding X coordinate?

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.

For example, we have a data file named "data.dat" like this

0.1     0.289010715
0.2     0.050630492
0.3     0.721247895
0.4     0.284271151
0.5     0.505051253
0.6     0.101819025
0.7     0.008466133
0.8     0.36249047
0.9     0.487576233
1.0     0.595090343
1.1     0.865255938
1.2     0.696628854
1.3     0.505899456
1.4     0.338131983
1.5     0.108034045

Run a gnuplot script as follows

reset
set term png
set output "max_min.png"
stats "data.dat" u 1:2 nooutput
set xrange [STATS_min_x:STATS_max_x]
set label 1 "Maximun" at STATS_pos_max_y, STATS_max_y offset 1,-0.5
set label 2 "Minimun" at STATS_pos_min_y, STATS_min_y offset 1,0.5
plot "data.dat" w p pt 3 lc rgb"#ff0000" notitle, \
     STATS_min_y w l lc rgb"#00ffff" notitle, \
     STATS_max_y w l lc rgb"#00ffff" notitle
set output

And you will get a graph like the following one.
Picking out the maximum and minimum points when plotting using gnuplot

12 comments:

  1. Thanks for the useful hint, but I'm using Debian with Gnuplot 4.4...

    And one more thing - just want to thank you for the excellent posts. Seriously. The posts about breaking the axis in gnuplot saved me a lot of time and allowed to prepare a conference proceeding. Thanks.

    ReplyDelete
    Replies
    1. Gnuplot Surprising: How To Pick Out The Maximum And Minimum Points When Plotting With Gnuplot? >>>>> Download Now

      >>>>> Download Full

      Gnuplot Surprising: How To Pick Out The Maximum And Minimum Points When Plotting With Gnuplot? >>>>> Download LINK

      >>>>> Download Now

      Gnuplot Surprising: How To Pick Out The Maximum And Minimum Points When Plotting With Gnuplot? >>>>> Download Full

      >>>>> Download LINK HC

      Delete
  2. What can one do when we have multiple data files to be plotted in the same graph and display the max, min values for each file?

    ReplyDelete
  3. ^same question here! Thanks in advance.

    ReplyDelete
  4. What if there are more than two columns and I am interested in, say, the maximum value of the 10th column?

    ReplyDelete
    Replies
    1. Then you do like this. http://gnuplot.sourceforge.net/demo_canvas_5.2/stats.html

      Delete
  5. Great post!

    What if you want STATS_pos_max_y to use the absolute values of y? In other words, -8 should be considered larger than 7.

    Also, I am printing STATS_pos_max_y on the plot and I can tell just by looking at the plot that the point is claims is the max, is not the max. How can this be? Is there a sampling frequency or something that could cause it to miss points?

    ReplyDelete
  6. I figured out that STATS_pos_max_y issue. I should have been using STATS_max_y. By switching the two, I was getting the y coordinate, not the y value. Still curious about finding the max of abs(y).

    Presumably I could create a new data set defined by something such as f(y) = abs(y) and then run STATS on the new data set, but that seems inelegant.

    ReplyDelete
  7. Compre documentos en línea, documentos originales y registrados.
    Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

    Comprar permiso de residencia,
    permiso de residenciareal y falso en línea,
    Compre licencia de conducir en línea,
    Compre una licencia de conducir española falsa en línea,
    Comprar tarjeta de identificación,
    Licencia de conducir real y falsa,
    Compre pasaporte real en línea,

    Visit Here fpr more information. :- https://permisodeespana.com/licencia-de-conducir-espanola/
    Address: 56 Guild Street, London, EC4A 3WU (UK)
    Email: contact@permisodeespana.com
    WhatsApp: +443455280186

    ReplyDelete
  8. Gnuplot Surprising: How To Pick Out The Maximum And Minimum Points When Plotting With Gnuplot? >>>>> Download Now

    >>>>> Download Full

    Gnuplot Surprising: How To Pick Out The Maximum And Minimum Points When Plotting With Gnuplot? >>>>> Download LINK

    >>>>> Download Now

    Gnuplot Surprising: How To Pick Out The Maximum And Minimum Points When Plotting With Gnuplot? >>>>> Download Full

    >>>>> Download LINK wn

    ReplyDelete

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.