How to get the coordinates of the extrema from a plot?
$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
12 hours ago
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago
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 13 hours ago
user3318424user3318424
874
874
$begingroup$
You mean aGraphics
-object or a pixel image?
$endgroup$
– Ulrich Neumann
12 hours ago
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago
add a comment |
$begingroup$
You mean aGraphics
-object or a pixel image?
$endgroup$
– Ulrich Neumann
12 hours ago
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago
$begingroup$
You mean a
Graphics
-object or a pixel image?$endgroup$
– Ulrich Neumann
12 hours ago
$begingroup$
You mean a
Graphics
-object or a pixel image?$endgroup$
– Ulrich Neumann
12 hours ago
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago
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
12 hours ago
$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
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
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$
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
12 hours ago
$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
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
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
12 hours ago
$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
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
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 11 hours ago
answered 12 hours ago
Ulrich NeumannUlrich Neumann
8,380516
8,380516
$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
12 hours ago
$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
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
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
12 hours ago
$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
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
$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
12 hours ago
$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
12 hours ago
$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
12 hours ago
$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
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
$begingroup$
All the extrema.
$endgroup$
– user3318424
12 hours ago
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 11 hours ago
Ulrich NeumannUlrich Neumann
8,380516
8,380516
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$
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$
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 10 hours ago
Bob HanlonBob Hanlon
59.5k33596
59.5k33596
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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');
var $window = $(window),
onScroll = function(e) {
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom)) {
StackExchange.using('gps', function() { StackExchange.gps.track('embedded_signup_form.view', { location: 'question_page' }); });
$window.unbind('scroll', onScroll);
}
};
$window.on('scroll', onScroll);
});
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
12 hours ago
$begingroup$
@UlrichNeumann I'm pretty sure they mean they have just a pixel image, which would complicate things a lot.
$endgroup$
– MassDefect
11 hours ago