Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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:

Manipulate[
 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

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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.

Manipulate[
  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


Note

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.

share|improve this answer
    
I switched the sin and cos graphs, but the intent should be clear. –  David Carraher May 24 '12 at 21:52
    
+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? –  Ajasja May 24 '12 at 21:55
    
@Ajasja I'm not sure why you want to use "paste snapshot". What are you trying to paste, and where? –  David Carraher May 24 '12 at 22:02
    
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" –  Ajasja May 24 '12 at 22:10
    
Apparently, the rendering of the PlotLabel depends on activation of Style. Dynamic apparently ensures that it is up to date. –  David Carraher May 24 '12 at 22:57
add comment

You could use Overlay:

Manipulate[
 Column[{Style[StringForm["Title `1`", Dynamic[p]], Large], Overlay[{
     Dynamic@
      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}}],
     Dynamic@
      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}]

Edit

manipulate

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.

share|improve this answer
    
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. –  Ajasja May 24 '12 at 21:57
    
@Ajasja Yes, you're right about the speed. Honestly, I don't like Manipulate. –  Jens May 24 '12 at 22:03
    
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 :) –  Ajasja May 24 '12 at 22:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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