How to get the coordinates of the extrema from a plot?
Clash Royale CLAN TAG#URR8PPP
$begingroup$
I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?
I am interested in getting the coordinates as pairs of x and y, for each color in the plot.
Here is an example of such an image:
plotting
$endgroup$
add a comment |
$begingroup$
I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?
I am interested in getting the coordinates as pairs of x and y, for each color in the plot.
Here is an example of such an image:
plotting
$endgroup$
$begingroup$
You mean aGraphics
-object or a pixel image?
$endgroup$
– Ulrich Neumann
Feb 1 at 16:07
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45
add a comment |
$begingroup$
I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?
I am interested in getting the coordinates as pairs of x and y, for each color in the plot.
Here is an example of such an image:
plotting
$endgroup$
I generated a number of plots. Let us assume that we now have these plots simply as an image. How do I get the coordinates of the extrema in this image?
I am interested in getting the coordinates as pairs of x and y, for each color in the plot.
Here is an example of such an image:
plotting
plotting
asked Feb 1 at 15:14
user3318424user3318424
874
874
$begingroup$
You mean aGraphics
-object or a pixel image?
$endgroup$
– Ulrich Neumann
Feb 1 at 16:07
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45
add a comment |
$begingroup$
You mean aGraphics
-object or a pixel image?
$endgroup$
– Ulrich Neumann
Feb 1 at 16:07
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45
$begingroup$
You mean a
Graphics
-object or a pixel image?$endgroup$
– Ulrich Neumann
Feb 1 at 16:07
$begingroup$
You mean a
Graphics
-object or a pixel image?$endgroup$
– Ulrich Neumann
Feb 1 at 16:07
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45
add a comment |
3 Answers
3
active
oldest
votes
$begingroup$
If "image" is a Graphics-object try
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20] (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)
Evaluate all extrema and plot
extrema = Map[Cases[
Partition[#, 3,1], _, a_, p : _, b_, _, c_ /; a < b && c < b || a > b && c > b -> p] &, lines]
Show[pic, Graphics[Point[extrema ]]]
$endgroup$
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
add a comment |
$begingroup$
If "image" is a pixel image
(named pic
, sorry, don't know how to include pic="image"
in the coding ) try:
dc = Rest@DominantColors[pic] (* dominant colors without white*)
curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)
Get the points of the different curves
points = Cases[curves , Point[pi_] -> pi, Infinity];
...see my first answer
$endgroup$
add a comment |
$begingroup$
Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks
to also catch the end points.
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20]; (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)
max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];
min = Flatten[(#[[FindPeaks[(# /. x_?NumericQ, y_?NumericQ :> x, -y)[[All,
2]]][[All, 1]]]] & /@ lines), 1];
Show[pic, Epilog -> AbsolutePointSize[4],
Red, Point[max],
Blue, Point[min]]
$endgroup$
$begingroup$
@ BobHanlon Thanks, I didn't knowFindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
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%2f190664%2fhow-to-get-the-coordinates-of-the-extrema-from-a-plot%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$
If "image" is a Graphics-object try
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20] (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)
Evaluate all extrema and plot
extrema = Map[Cases[
Partition[#, 3,1], _, a_, p : _, b_, _, c_ /; a < b && c < b || a > b && c > b -> p] &, lines]
Show[pic, Graphics[Point[extrema ]]]
$endgroup$
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
add a comment |
$begingroup$
If "image" is a Graphics-object try
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20] (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)
Evaluate all extrema and plot
extrema = Map[Cases[
Partition[#, 3,1], _, a_, p : _, b_, _, c_ /; a < b && c < b || a > b && c > b -> p] &, lines]
Show[pic, Graphics[Point[extrema ]]]
$endgroup$
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
add a comment |
$begingroup$
If "image" is a Graphics-object try
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20] (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)
Evaluate all extrema and plot
extrema = Map[Cases[
Partition[#, 3,1], _, a_, p : _, b_, _, c_ /; a < b && c < b || a > b && c > b -> p] &, lines]
Show[pic, Graphics[Point[extrema ]]]
$endgroup$
If "image" is a Graphics-object try
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20] (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity] (*get the points*)
Evaluate all extrema and plot
extrema = Map[Cases[
Partition[#, 3,1], _, a_, p : _, b_, _, c_ /; a < b && c < b || a > b && c > b -> p] &, lines]
Show[pic, Graphics[Point[extrema ]]]
edited Feb 1 at 16:33
answered Feb 1 at 15:37
Ulrich NeumannUlrich Neumann
9,001516
9,001516
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
add a comment |
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
Thank you for your answer. However, I assume that I no longer have or know the function that resulted in the plots. I only have the "image".
$endgroup$
– user3318424
Feb 1 at 15:41
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
I didn't use the knowledge of the function! One questiom : Are you looking for all extrema or only the global?
$endgroup$
– Ulrich Neumann
Feb 1 at 15:42
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
$begingroup$
All the extrema.
$endgroup$
– user3318424
Feb 1 at 15:46
add a comment |
$begingroup$
If "image" is a pixel image
(named pic
, sorry, don't know how to include pic="image"
in the coding ) try:
dc = Rest@DominantColors[pic] (* dominant colors without white*)
curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)
Get the points of the different curves
points = Cases[curves , Point[pi_] -> pi, Infinity];
...see my first answer
$endgroup$
add a comment |
$begingroup$
If "image" is a pixel image
(named pic
, sorry, don't know how to include pic="image"
in the coding ) try:
dc = Rest@DominantColors[pic] (* dominant colors without white*)
curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)
Get the points of the different curves
points = Cases[curves , Point[pi_] -> pi, Infinity];
...see my first answer
$endgroup$
add a comment |
$begingroup$
If "image" is a pixel image
(named pic
, sorry, don't know how to include pic="image"
in the coding ) try:
dc = Rest@DominantColors[pic] (* dominant colors without white*)
curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)
Get the points of the different curves
points = Cases[curves , Point[pi_] -> pi, Infinity];
...see my first answer
$endgroup$
If "image" is a pixel image
(named pic
, sorry, don't know how to include pic="image"
in the coding ) try:
dc = Rest@DominantColors[pic] (* dominant colors without white*)
curves = Map[ListPlot[PixelValuePositions[pic, #, .1 ],Axes -> False, PlotStyle -> #] &, dc] (* three colored curves *)
Get the points of the different curves
points = Cases[curves , Point[pi_] -> pi, Infinity];
...see my first answer
answered Feb 1 at 17:06
Ulrich NeumannUlrich Neumann
9,001516
9,001516
add a comment |
add a comment |
$begingroup$
Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks
to also catch the end points.
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20]; (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)
max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];
min = Flatten[(#[[FindPeaks[(# /. x_?NumericQ, y_?NumericQ :> x, -y)[[All,
2]]][[All, 1]]]] & /@ lines), 1];
Show[pic, Epilog -> AbsolutePointSize[4],
Red, Point[max],
Blue, Point[min]]
$endgroup$
$begingroup$
@ BobHanlon Thanks, I didn't knowFindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
add a comment |
$begingroup$
Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks
to also catch the end points.
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20]; (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)
max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];
min = Flatten[(#[[FindPeaks[(# /. x_?NumericQ, y_?NumericQ :> x, -y)[[All,
2]]][[All, 1]]]] & /@ lines), 1];
Show[pic, Epilog -> AbsolutePointSize[4],
Red, Point[max],
Blue, Point[min]]
$endgroup$
$begingroup$
@ BobHanlon Thanks, I didn't knowFindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
add a comment |
$begingroup$
Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks
to also catch the end points.
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20]; (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)
max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];
min = Flatten[(#[[FindPeaks[(# /. x_?NumericQ, y_?NumericQ :> x, -y)[[All,
2]]][[All, 1]]]] & /@ lines), 1];
Show[pic, Epilog -> AbsolutePointSize[4],
Red, Point[max],
Blue, Point[min]]
$endgroup$
Ulrich's approach for a Graphics-object misses the end points. You can use FindPeaks
to also catch the end points.
pic = Plot[Sin[x]/x, Exp[-.1 x] Sin[x], x, 0, 20]; (*two functions*)
lines = Cases[pic, Line[p_] -> p, Infinity]; (*get the points*)
max = Flatten[(#[[FindPeaks[#[[All, 2]]][[All, 1]]]] & /@ lines), 1];
min = Flatten[(#[[FindPeaks[(# /. x_?NumericQ, y_?NumericQ :> x, -y)[[All,
2]]][[All, 1]]]] & /@ lines), 1];
Show[pic, Epilog -> AbsolutePointSize[4],
Red, Point[max],
Blue, Point[min]]
answered Feb 1 at 17:45
Bob HanlonBob Hanlon
60.6k33597
60.6k33597
$begingroup$
@ BobHanlon Thanks, I didn't knowFindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
add a comment |
$begingroup$
@ BobHanlon Thanks, I didn't knowFindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
$begingroup$
@ BobHanlon Thanks, I didn't know
FindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
$begingroup$
@ BobHanlon Thanks, I didn't know
FindPeaks
$endgroup$
– Ulrich Neumann
Feb 2 at 9:35
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%2f190664%2fhow-to-get-the-coordinates-of-the-extrema-from-a-plot%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$
You mean a
Graphics
-object or a pixel image?$endgroup$
– Ulrich Neumann
Feb 1 at 16:07
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
Feb 1 at 16:45