Tracking dynamic markers across plots (Mathematica)

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 2K views
Swamp Thing
Insights Author
Messages
1,062
Reaction score
819
TL;DR
Use slider to move coupled markers in two or more plots, without triggering recalc of curves.
Let's say we have a rectangular plot of two curves X(t) and Y(t); and next to it we have a parametric plot of (X(t) , Y(t)).

Now we want to add a slider that can control markers on both plots, so that the slider ( = ts) moves two markers X(ts) and Y(ts) across the rectangular plot and at the same time another linked marker at [X(ts),Y(ts)] travels along the parametric curve in the other plot.

Also, we don't want the curves themselves to be dynamic, i.e. we don't want recalculation of the curves when the slider is moved.

How can we achieve this in Mathematica? One issue I found is that it won't allow us to Show[] a dynamic and static plot combined, which rules out one approach that I tried.
 
Physics news on Phys.org
Swamp Thing said:
One issue I found is that it won't allow us to Show[] a dynamic and static plot combined, which rules out one approach that I tried.
Hmm, I found that this worked:
Code:
tmp = Plot[Sin[x], {x, -2 \[Pi], 2 \[Pi]}]
Manipulate[Show[tmp, Graphics[Point[{1, y}]]], {y, -1, 1}]
 
  • Like
Likes   Reactions: Swamp Thing
I was trying something like this...

X=1.234;
P1 = Plot[... something...] ;
P2= Dynamic[ Plot[ .. something else involving X..]]

P2 (* this worked ok *)
Show[P1,P2] (* this gave an error *)

So P2 on its own would work dynamically off of X, but if I tried Show[P1, P 2] it would throw an error like "Cannot combine objects P1, P2 etc etc...". If I removed the dynamic input from P2, the Show[] would work.
 
There is a more general thing that I hadn't realized (although it now seems fairly obvious after applying your suggestion). Variables assigned outside of a Manipulate are treated as static, i.e. Manipulate doesn't respond to changes in their values.

I verified this by plotting a function that, before returning its value, would increment a counter. Using your tip, one could see that the counter wouldn't increment when you moved the slider. But if you put the Plot definition directly in the Manipulate, then the counter would increment by 300+ each time you move the marker -- even though the plotted function didn't contain the slider variable.
 
  • Like
Likes   Reactions: Dale