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}]
I know this can be done using Dynamic
, but then I loose some features of manipulate, such as "Paste Snapshoot", "Make Bookmark" and SaveDefinitions
Answer
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}]
Note
Normally one confines a Locator to a particular region using optional parameters in LocatorPane
:
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.
Comments
Post a Comment