I am trying to create a Manipulate module that shows two plots, and have locators on each of those plots, as well as two sliders. The locators do do not affect each other's position, but one of the locators affects both sliders, and vice versa. Here is a minimal version of my current code:

   Plot[(x - a)^2 + b, {x, 0, 1}, ImageSize -> Medium, 
    PlotRange -> {0, 1}],
   Plot[{(x - pt[[1]])^2 + pt[[2]], b}, {x, 0, 1}, ImageSize -> Medium, 
    PlotRange -> {0, 1}, GridLines -> {{a}, {}}, 
    Epilog -> {PointSize[Large], Point[Dynamic@{a, b}]}]}],
 {a, 0, 1}, {b, 0, 1}, {{pt, {0, 1}}, Locator}]

This is a screenshot of the scenario:

enter image description here

In the code above only one locator is declared. The other locator I would like to declare should be at {a,b} in the second plot. I've made the point Dynamic, but it doesn't do anything when I try to click-drag with my mouse. I've seen this question about locators and sliders affecting each other, but there only one graph has an interactive locator, and I would like both to have an interactive locator. I also tried to get some intuition from this question about specifying which element of Grid a locator should affect, but I am not an expert Mathematica user, so I couldn't adapt it.

So, my question is:

How can I get two independent locators, each in a different plot, one of which depends on sliders?

  • $\begingroup$ What is the second locator supposed to do ? $\endgroup$
    – Lotus
    May 16, 2019 at 3:53
  • $\begingroup$ The second locator should be at the coordinate {a, b} in the second plot, and moving it should change the a and b sliders. This also affects the first plot. $\endgroup$ May 16, 2019 at 3:55

1 Answer 1


Is this what you need ? :

DynamicModule[{pt1 = {0.5, 0.5}, a = .6, b = .2}
 , Column[{
   Manipulator[Dynamic[a], {0, 1}],
   Manipulator[Dynamic[b], {0, 1}],
      Dynamic @ Plot[(x - a)^2 + b, {x, 0, 1}, ImageSize -> Medium, 
            PlotRange -> {0, 1}]]
     , LocatorPane[Dynamic[{a, b}], 
      Dynamic @ 
       Plot[{(x - a)^2 + b, b}, {x, 0, 1}, ImageSize -> Medium, 
            PlotRange -> {0, 1}, GridLines -> {{a}, {}}, 
            Epilog -> {PointSize[Large], Point[Dynamic@{a, b}]}]]

enter image description here

  • $\begingroup$ Nice! Almost, the second plot should be (x-pt1[[1]])^2+pt1[[2]], and that works as desired. This does answer my question, b̶u̶t̶ ̶-̶ ̶w̶h̶a̶t̶ ̶i̶f̶ ̶I̶ ̶h̶a̶v̶e̶ ̶t̶w̶o̶ ̶l̶o̶c̶a̶t̶o̶r̶s̶ ̶i̶n̶ ̶t̶h̶e̶ ̶f̶i̶r̶s̶t̶ ̶p̶l̶o̶t̶?̶ ̶I̶s̶ ̶t̶h̶e̶r̶e̶ ̶a̶n̶ ̶e̶a̶s̶y̶ ̶w̶a̶y̶ ̶t̶o̶ ̶d̶o̶ ̶t̶h̶a̶t̶ ̶o̶n̶ ̶t̶o̶p̶ ̶o̶f̶ ̶t̶h̶i̶s̶?̶ Figured it out, just put Dynamic[{pt1,pt2}] in LocatorPane. Thanks for your help. $\endgroup$ May 16, 2019 at 18:57

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.