2
$\begingroup$

When only the g1 graph was drawn, the locator was in the desired position. However, when I expressed the two graphs vertically using the Coulmn function, the position of the locator changed. How can I make the locator stay at g1?

 Manipulate[ g1 = Plot[1, {x, 0, 1}, PlotLabel -> "g1"]; g1, {p, {0.5, 0}, Locator}] 

enter image description here

Manipulate[g1 = Plot[1, {x, 0, 1}, PlotLabel -> "g1"]; g2 = Plot[x, {x, 0, 1}, PlotLabel -> "g2"]; Column[{g1, g2}], {p, {0.5, 0}, Locator}] 

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ I think Locator goes with one Graphics object. You have two. You can't make it jump graphics. So you need to combine both plots into one Graphics to make it work, or use two different locators? Look at help pages and all examples show one Graphics object with one locator. $\endgroup$ Commented Dec 16, 2023 at 16:56

2 Answers 2

3
$\begingroup$

If you want to restrict the locator to g1 and draw g1 and g2, you can write (note the extra braces around p,{0.5,0}):

g1 = Plot[1, {x, 0, 1}, PlotLabel -> "g1"]; g2 = Plot[x, {x, 0, 1}, PlotLabel -> "g2", ImageSize -> 400]; Column[{Manipulate[g1, {{p, {0.5, 0}}, Locator}] , g2}] 

enter image description here

Addendum

According to your comment, if you want to make p available in g2, simply put it into a globale variable (e.g. p0). Here I use it in the "PlotLable" of g2:

g1 = Plot[1, {x, 0, 1}, PlotLabel -> "g1", ImageSize -> 400]; g2 = Plot[x, {x, 0, 1}, PlotLabel -> StringForm["p= ``", Dynamic[p0]], ImageSize -> 400]; Column[{Manipulate[{p0 = p; g1}, {{p, {0.5, 0}}, Locator}], g2}] 

enter image description here

$\endgroup$
2
  • $\begingroup$ Thank you for yout reply. Could I have further question? If the location of p should be known to Graph g2, what should be modifed? For example, in this code: Column[{Manipulate[ Plot[1, {x, 0, 1}, PlotLabel -> "g1"], {p, {0.5, 0}, Locator}], Plot[x, {x, p[[1]], 1}, PlotLabel -> "g2", ImageSize -> 400]} ] (Of course it doesn't work because p[[1]] is not known to g2) $\endgroup$ Commented Dec 18, 2023 at 14:09
  • 1
    $\begingroup$ Look at my addendum. $\endgroup$ Commented Dec 18, 2023 at 15:10
2
$\begingroup$

Not a answer

I can't reproduce your problem on my machine.

With your code I obtain what you would like to do :

$Version Manipulate[g1 = Plot[1, {x, 0, 1}, PlotLabel -> "g1"]; g2 = Plot[x, {x, 0, 1}, PlotLabel -> "g2"]; Column[{g1, g2}], {p, {0.5, 0}, Locator}] 

12.2.0 for Microsoft Windows (64-bit) (December 12, 2020)

enter image description here

$\endgroup$
1
  • 2
    $\begingroup$ I reproduce OP's problem in 13.3 for Windows $\endgroup$ Commented Dec 16, 2023 at 22:05

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.