I managed to evaluate a function using a locator on a contour plot with the following code:

f[x_, y_] := -x + x^2 + 2 y^2
LocatorPane[Dynamic[pt], ContourPlot[f[x, y], {x, -1, 1}, {y, -1, 1}],
  Appearance -> Dynamic[f[pt[[1]], pt[[2]]]]]

which gives this image:

contour plot and locator

Would any of my colleagues like to suggest a cuter way? Maybe one that shows the locator and puts the function value as a plot label or some such thing? Something cool and easy for students new to Mathematica to easily understand?

The purpose of this activity is to help students guess where the maximum and minimum values lie over this region.


1 Answer 1


A simple example:

DynamicModule[{pt}, LocatorPane[Dynamic[pt], 
              ContourPlot[f[x, y], {x, -1, 1}, {y, -1, 1}, 
                          PlotLabel -> Row[{"Point: ",
                                            Dynamic[Append[pt, f[pt[[1]], pt[[2]]]]]}]]]]

locator showing coordinates

  • 1
    $\begingroup$ Thanks J.M. My colleague really liked this suggestion. Really helpful. $\endgroup$
    – David
    Commented Apr 11, 2017 at 5:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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