Let's take this example:

DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]

How do I retrieve the minimum value and position of the minimum of a plot from the plot? How do I tell Mathematica to mark the position of the minimum/minima within the plot?

And for ContourPlots

ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}]

Is there a way to mark the exact minimum position within the plot even though it's a contour plot?

Yes, Jens and Szabolcs, that would be the best way if i could manage to write the code for that. I'm still a beginner with mathematica and haven't managed so far to cope with that problem because....well i think i have to post a piece of my code to show it. I have deleted most of the variables and replaced them by constants for simplicity reasons:

eislexpl[epsilon_, n2_, x_] :=  28 (epsilon)^2 - 1 + 
((-2 Log[E^(1/2) x])/x^2 + (2.7(0.3 - epsilon))/x + 
(10 epsilon^2 n2^(3/2))/x^(3/2));

eislminx2[epsilon_?NumericQ, n2_?NumericQ] := 
(minx = FindArgMin[{eislexpl[epsilon, n2, x], 0 < x}, x];
eislexpl[epsilon, n2, minx]);

ueislexpl[epsilon_, h_, n1_, n2_] := 
n1 (40  epsilon^2 - 1) + (1 -1.27 ) (1 + (n1 - 1) HeavisideTheta[1 - n1] - 
(-1 + Exp[-(n1 - 1)]) HeavisideTheta[n1 - 1]) + n2  eislminx2[epsilon, n2] + 
(h - n1 - n2) (28  epsilon^2 - 1);

ueislexpl[epsilon_, h_, n1_, n2_] is the function i need to find the minimum for. But the problem for me is, that it calls this function eislminx[epsilon_?NumericQ,n2_?NumericQ]. So my problem is that in order to have a function that mathematica is able to find a minimum for, i have to plug n2 in eislminx[epsilon_?NumericQ,n2_?NumericQ], so that this part of ueislexpl[epsilon_, h_, n1_, n2_] determined, but at the same time i want to find the minimum for ueislexpl[epsilon_, h_, n1_, n2_] with respect to n2. So if anybody know how to find the minimum of ueislexpl[epsilon_, h_, n1_, n2_] with respect to n2 and n1 i would be happy to learn how.

Thanks for the help.

Well, my actual question has been answered by kguler, thanks again ;) And the question of how to find the minimum of that function above i will source out to here: Finding the minimum of a function

  • $\begingroup$ Look up FindMinimum, Minimize, and Epilog. $\endgroup$
    – Jens
    Aug 8, 2014 at 18:33
  • $\begingroup$ As Jens suggests, first find the minimum of the function, and then add it to the plot. $\endgroup$
    – Szabolcs
    Aug 8, 2014 at 18:34
  • $\begingroup$ Dealing with multiple global minima is likely going to be difficult. Do you really need this, or would you be satisfied with a single minimum? Are you working with analytical functions or numerical blackboxes? $\endgroup$
    – Szabolcs
    Aug 8, 2014 at 18:37
  • $\begingroup$ @Szabolcs, do you thin this can be done be extracting info from FullForm of the plot? $\endgroup$ Aug 8, 2014 at 18:42
  • $\begingroup$ @Algohi I'm sure it can be done, but why would anyone go to all that trouble if they already have the function available? Also, it's probably not going to be very precise when done that way, so it's much simpler to just find it "by eye" (assuming that only the plot is available and the function used to make the plot was lost). $\endgroup$
    – Szabolcs
    Aug 8, 2014 at 19:08

2 Answers 2


A quick-and-dirty way: get the contours for the .0000001st and .9999999th quantiles as approximations for min and max

dp = DensityPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}];
cp1 = ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3}, 
            ContourShading -> None, 
            ContourStyle -> {Directive[Red, Thick], Directive[Orange, Thick]}, 
            Contours -> Function[{min, max}, 
                          Rescale[{.00000001, .99999999999}, {0, 1}, {min, max}]]];
cp2 = ContourPlot[Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},  ContourShading -> None];
Legended[Show[dp, cp1, cp2], 
             PointLegend[{Red, Orange}, {"min", "max"}, LabelStyle -> 16, 
                         BaseStyle -> PointSize[Large]]]

enter image description here

  • $\begingroup$ Thanks again for your help, kguler, that works just fine :) $\endgroup$ Aug 9, 2014 at 5:55
min = Minimize[
   {Sin[x] Sin[y], -4 < x < 4, -3 < y < 3},
   {x, y}][[1]]


minPts = Cases[
  Reduce[{Sin[x] Sin[y] == min, -4 < x < 4, -3 < y < 3}, {x, 
    y}], (x == x1_ && y == y1_) :> {x1, y1}, Infinity]

{{-(Pi/2), Pi/2}, {Pi/2, -(Pi/2)}}

 Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},
 Epilog ->
  {Red, AbsolutePointSize[6], Point[minPts]}]

enter image description here

 Sin[x] Sin[y], {x, -4, 4}, {y, -3, 3},
 Epilog ->
  {Red, AbsolutePointSize[6], Point[minPts]}]

enter image description here

  • $\begingroup$ you could also use ArgMin[{Sin[x] Sin[y], -4 < x < 4, -3 < y < 3}, {x, y}] $\endgroup$
    – chris
    Aug 9, 2014 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.