Gnuplot: how to plot the maximum and / or minimum value

How to show max. and / or min. the graph values ​​(s) in the graph at their appropriate position automatically?


source to share

1 answer

You can do this "semi-automatically" with the command stats

. This command can extract some statistical values ​​from a dataset, but requires some tweaking:

  • Extract the minimum and maximum y values, assuming your data file has two columns, the x value in the first, y values ​​in the second column

    stats 'file.dat' using 2 nooutput name 'Y_'

    This gives the minimum / maximum y-values ​​in the variables Y_min

    and Y_max

    , but not the corresponding x-value.

  • In the previous step, you only get the corresponding indices, for which you need to run again stats

    to get the x values:

     stats 'file.dat' using 1 every ::Y_index_min::Y_index_min nooutput
     X_min = STATS_min
     stats 'file.dat' using 1 every ::Y_index_max::Y_index_max nooutput
     X_max = STATS_max

  • Set labels and / or points at the appropriate coordinates

    set label 1 sprintf("%.2f", Y_min) center at first X_min,Y_min point pt 7 ps 1 offset 0,-1.5
    set label 2 sprintf("%.2f", Y_max) center at first X_max,Y_max point pt 7 ps 1 offset 0,1.5
    plot ...



All Articles