Finding minimum from ListPlot
$begingroup$
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.
plotting list-manipulation mathematical-optimization peak-detection
$endgroup$
add a comment |
$begingroup$
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.
plotting list-manipulation mathematical-optimization peak-detection
$endgroup$
$begingroup$
Data[[Ordering[Data[[All,2]],1][[1]],1]]
?
$endgroup$
– Henrik Schumacher
12 hours ago
add a comment |
$begingroup$
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.
plotting list-manipulation mathematical-optimization peak-detection
$endgroup$
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.
plotting list-manipulation mathematical-optimization peak-detection
plotting list-manipulation mathematical-optimization peak-detection
edited 23 mins ago
Community♦
1
1
asked 12 hours ago
JohnJohn
32016
32016
$begingroup$
Data[[Ordering[Data[[All,2]],1][[1]],1]]
?
$endgroup$
– Henrik Schumacher
12 hours ago
add a comment |
$begingroup$
Data[[Ordering[Data[[All,2]],1][[1]],1]]
?
$endgroup$
– Henrik Schumacher
12 hours ago
$begingroup$
Data[[Ordering[Data[[All,2]],1][[1]],1]]
?$endgroup$
– Henrik Schumacher
12 hours ago
$begingroup$
Data[[Ordering[Data[[All,2]],1][[1]],1]]
?$endgroup$
– Henrik Schumacher
12 hours ago
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
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[1] // 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 ]
$endgroup$
add a comment |
$begingroup$
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]
$endgroup$
add a comment |
$begingroup$
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]]-#1[[1]] <= 0.0011 &][[All, {1,-1}]]
maybe combined with Flatten
to make into a single list of points.
$endgroup$
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191251%2ffinding-minimum-from-listplot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
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[1] // 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 ]
$endgroup$
add a comment |
$begingroup$
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[1] // 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 ]
$endgroup$
add a comment |
$begingroup$
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[1] // 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 ]
$endgroup$
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[1] // 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 ]
answered 11 hours ago
gwrgwr
8,42322761
8,42322761
add a comment |
add a comment |
$begingroup$
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]
$endgroup$
add a comment |
$begingroup$
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]
$endgroup$
add a comment |
$begingroup$
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]
$endgroup$
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]
edited 9 hours ago
answered 10 hours ago
kglrkglr
183k10201416
183k10201416
add a comment |
add a comment |
$begingroup$
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]]-#1[[1]] <= 0.0011 &][[All, {1,-1}]]
maybe combined with Flatten
to make into a single list of points.
$endgroup$
add a comment |
$begingroup$
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]]-#1[[1]] <= 0.0011 &][[All, {1,-1}]]
maybe combined with Flatten
to make into a single list of points.
$endgroup$
add a comment |
$begingroup$
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]]-#1[[1]] <= 0.0011 &][[All, {1,-1}]]
maybe combined with Flatten
to make into a single list of points.
$endgroup$
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]]-#1[[1]] <= 0.0011 &][[All, {1,-1}]]
maybe combined with Flatten
to make into a single list of points.
edited 9 hours ago
answered 10 hours ago
RomanRoman
1,012511
1,012511
add a comment |
add a comment |
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191251%2ffinding-minimum-from-listplot%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Data[[Ordering[Data[[All,2]],1][[1]],1]]
?$endgroup$
– Henrik Schumacher
12 hours ago