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 |

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

ReplyDeleteAnd 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.

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^same question here! Thanks in advance.

ReplyDeleteGreat post

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

ReplyDeleteThen you do like this. http://gnuplot.sourceforge.net/demo_canvas_5.2/stats.html

Deletenice blog

ReplyDeletedata science training in bangalore

hadoop training in bangalore

IOT Training in Bangalore - Live Online & Classroom

ReplyDeleteIot Training course observes iot as the platform for networking of different devices on the internet and their inter related communication. Iot Training in Bangalore

Gaining Python certifications will validate your skills and advance your career.

ReplyDeletepython certification

Great post!

ReplyDeleteWhat 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?

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).

ReplyDeletePresumably 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.