I would like to restrict the Locator inside Manipulate to a certain graphic. For example if I display two graphs, I would like to be able to click on the right one and use this information in other places (for example in the title and the left graph). By design, Manipulate assigns the Locator to the first graphic object that it displays (see under Details and Options). How can this be overcome?

Here is an example snippet:

 sin =
  Plot[Sin[x], {x, -5, 5}, ImageSize -> Medium, 
   Epilog -> {Red, PointSize[Large], Point[p]}];
 cos = Plot[Cos[x], {x, -5, 5}, 
   PlotLabel -> "I would like to have the locator on this graph!", 
   ImageSize -> Medium, Epilog -> {Green, PointSize[Large], Point[p]}];
 Column[{Style[StringForm["Title `1`", p], Large],
   Row[{sin, cos}]}, Center],
 {{p, {0, 0}}, {-5, -5}, {5, 5}, ControlType -> Locator}]

example output

I know this can be done using Dynamic, but then I loose some features of manipulate, such as "Paste Snapshoot", "Make Bookmark" and SaveDefinitions


2 Answers 2


Edit: I am replacing my first attempt with another. The locator-point in the right graph controls the information in the title as well as the point in the left graph.

The point on the right could be made to appear like a locator by replacing Point with an appropriate-looking graphics object.

  Column[{Style[StringForm["Title `1`", Dynamic@pt], Large], 
       Row[{Plot[Cos[x], {x, -5, 5}, 
       Epilog -> {PointSize[Large], Point[Dynamic[{First[pt], Cos[First[pt]]}]]}, 
       ImageSize -> 300], 
       LocatorPane[Dynamic[pt], Plot[Sin[x], {x, -5, 5}, 
         Epilog -> {PointSize[Large], 
         Point[Dynamic[{First[pt], Sin[First[pt]]}]]}, 
         ImageSize -> 300, 
         PlotLabel -> "I would like to have the locator on this graph!"], 
       Appearance -> None]}]}, Center], {{pt, {0, 1}}, None}]

locator on right


Normally one confines a Locator to a particular region using optional parameters in LocatorPane:

LocatorPane instructions

However, it is not necessary to do this above because the LocatorPane sits in a single cell in the table. The locator cannot exceed the bounds of that cell.

  • $\begingroup$ I switched the sin and cos graphs, but the intent should be clear. $\endgroup$
    – DavidC
    May 24, 2012 at 21:52
  • $\begingroup$ +1 Thanks! Do you perhaps have an idea, why the title is messed up, when you do "Paste snapshot"? (And why it works if I pout the Dynamic around Style instead of pt? $\endgroup$
    – Ajasja
    May 24, 2012 at 21:55
  • $\begingroup$ @Ajasja I'm not sure why you want to use "paste snapshot". What are you trying to paste, and where? $\endgroup$
    – DavidC
    May 24, 2012 at 22:02
  • $\begingroup$ The paste snapshot is available when you click the + in the upper right corner of the manipulate pane. If I try to evaluate the new cell then the title does not seam to get the value. I want to use this to bookmark interesting parameter combinations as shown here under "Bookmarking Combinations of Parameter Values" $\endgroup$
    – Ajasja
    May 24, 2012 at 22:10
  • $\begingroup$ Apparently, the rendering of the PlotLabel depends on activation of Style. Dynamic apparently ensures that it is up to date. $\endgroup$
    – DavidC
    May 24, 2012 at 22:57

You could use Overlay:

 Column[{Style[StringForm["Title `1`", Dynamic[p]], Large], Overlay[{
      Plot[Cos[x], {x, -5, 5}, 
       PlotLabel -> 
        "I would like to have the locator on this graph!",
       ImageSize -> Large, 
       Epilog -> {Green, PointSize[Large], Point[p]}, 
       PlotRegion -> {{0.5, 1}, {0, 1}}],
      Plot[Sin[x], {x, -5, 5}, ImageSize -> Large, 
       Epilog -> {Red, PointSize[Large], Point[p]},
       PlotRegion -> {{0, .5}, {0, 1}}, 
       PlotLabel -> "Not on this graph!"]
     }, All, 1]}, Center],
 {{p, {0, 0}}, {-5, -1}, {5, 1}, ControlType -> Locator}]



I added explicit Dynamic around objects depending on p to prevent sporadic loss of mouse tracking, and to hopefully speed up the response. The documentation for Manipulate states:

In the form {u,Locator}, the value of u is a list giving x and y coordinates. The coordinates refer either to the first graphic in expr, or range from 0 to 1 in each direction across expr.

Here I'm relying on the coordinates of the first graphic in the Overlay expression.

What I did to arrange the graphics horizontally is simply to set their PlotRegion option to leave either the left or right half of the surrounding space empty. In the Overlay, they then fill the two halves to form what looks like a row.

  • $\begingroup$ Due to the way my other data is laid out I would like the locator be on the right. This works by setting Overlay[{sin, cos}], although I have no idea why. Also with Overlay manipulate seems to respond slower than with LocatorPane. $\endgroup$
    – Ajasja
    May 24, 2012 at 21:57
  • $\begingroup$ @Ajasja Yes, you're right about the speed. Honestly, I don't like Manipulate. $\endgroup$
    – Jens
    May 24, 2012 at 22:03
  • $\begingroup$ Yes, sadly I had a lot of problems as well. Although with a bit of tweaking and hacking and workarounds I get there eventually. I hope this will improve in mma 9 :) $\endgroup$
    – Ajasja
    May 24, 2012 at 22:07
  • $\begingroup$ There is a problem with this solution: the locator moves even if I click in the "Title" section, so it is not really restricted to the right plot region. $\endgroup$
    – shrx
    Feb 8, 2016 at 12:28
  • $\begingroup$ @shrx The locator is restricted to the right plot region. I just tried it. It does move to the edge of the region if you click as you describe, but it never leaves that region. $\endgroup$
    – Jens
    Feb 8, 2016 at 15:25

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.