0
$\begingroup$

I have a Dynamic inside LocatorPane which provides a value to be used in several other places. The idea is to have a Plot that automatically updates once the Locator changes value. First, I define a point and a Locator control restricted to the unit disk:

pt = {1/2, 0};
LocatorPane[Dynamic[pt, (pt = #; pt = Function[{pnt}, If[Norm[pnt, 2] < 1, pnt, Normalize[pnt, 
(Norm[#, 2] &)]]] /@pt) &], Graphics[{LightGray, Disk[{0, 0}, 1]}, ImageSize -> 100]]

Next, I set up the plot to draw a horizontal line at the Locator's current y-value:

Plot[pt[[2]], {x, -5, 5}]

This works, but the plot is not auto-updated once the Locator changes position. Interestingly, Dynamic[pt[[2]]] works if used standalone but not inside the plot. How can I make this work?


Edit: As suggested in the comments, enclosing the plot in Dynamic does the trick.

There is a similar issue where that does not work, apparently:

ContourPlot[{[f[1, C1, C2] == 0, g[2, C1, C2] == Pi/2}, {C1, -6, 6}, {C2, -6, 6}]

with f[x,C1,C2], g[x,C1,C2] being dependent on (dynamic) x and the real parameters $C1$, $C2$. These functions will intersect depending on $C1$, $C2$, so I tried to wrap ContourPlot inside Dynamic, and also each function separately. Why is ContourPlot evading my efforts?

$\endgroup$
2
  • 2
    $\begingroup$ tried Dynamic[Plot[pt[[2]], {x, -5, 5}]]? $\endgroup$
    – kglr
    Commented Aug 11, 2021 at 20:19
  • $\begingroup$ @kglr: That was it. There is a ContourPlot where that does not work, though. $\endgroup$ Commented Aug 11, 2021 at 23:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.