# Finding minimum from ListPlot

I have Table with 10000 elements in it and I plot a graphic using ListPlot. I need find minimum in graph. Here is a .txt file with data.

I tried to use

Min[Data[[All,1]]]


the result is 0., cuz it search the first point of x but I don't need the first one.

• Data[[Ordering[Data[[All,2]],1][],1]]? – Henrik Schumacher Feb 10 at 15:56

This is how I would go about it:

minIndex = data[[All, 2]] // MinDetect // PositionIndex;


Now all the positions of the minima were collected in an Association and given the key 1. We now want to split the list of minima positions into sublists that are "connected", e.g. where each position is separated by a distance of 1. From these sublists we only need the first and the last positions (the "corners"):

minPositions = minIndex // RightComposition[
Split[#, #1 == #2 - 1 &] & (* distance could be made more "soft" of course *)
, Part[#, All, {1, -1}] &
, Flatten
]


{1, 276, 1167, 2844}

We now Extract the data points for these positions dropping the first, which you do not need as you said:

minPoints = Extract[data, List /@ minPositions] // Drop[#, 1] &


{{0.275, 0.}, {1.166, 0.}, {2.843, 0.}}

Finally:

ListPlot[ data, Epilog -> {Red, PointSize -> Large, Point@minPoints }, ImageSize -> Large ] lp = ListLinePlot[data,
MeshFunctions -> {#2 &},
MeshStyle -> Directive[Red, PointSize[Large]],
Mesh -> {{Min[data[[All, 2]]]}},
AxesOrigin -> {0, -.01}] To extract the data elements:

Cases[Normal @ lp, Point[x_] :> x, All]


{{0., 0.}, {0.275, 0.}, {1.166, 0.}, {2.843, 0.}}

If you want to remove the first point:

lp /. Point[x_] :> Point[Rest @ x] This should do:

MinimalBy[Data, Last]


If you have runs of minimal elements and only want the first and last one: assuming that the grid spacing is 0.001 and inserting 10% of tolerance,

Split[MinimalBy[Data, Last], #2[]-#1[] <= 0.0011 &][[All, {1,-1}]]


maybe combined with Flatten to make into a single list of points.