Mathematica Tracking dynamic markers across plots (Mathematica)

AI Thread Summary
The discussion centers on creating a synchronized visualization in Mathematica involving two plots: a rectangular plot of curves X(t) and Y(t), and a parametric plot of (X(t), Y(t)). The goal is to implement a slider that controls markers on both plots simultaneously without recalculating the curves when the slider is adjusted. A key issue arises with the Show[] function, which does not allow the combination of dynamic and static plots. One participant successfully demonstrates a workaround using Manipulate to display a static plot alongside a dynamic point, highlighting that variables assigned outside of Manipulate are treated as static and do not respond to slider changes. This insight reveals that placing plot definitions directly within Manipulate allows for dynamic behavior, enabling the counter to increment with slider movements, even if the plotted function does not directly reference the slider variable.
Swamp Thing
Insights Author
Messages
1,032
Reaction score
770
TL;DR Summary
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 Swamp Thing
Perfect... thanks!
 
What was it with Show that wasn’t working for you?
 
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 Dale

Similar threads

Replies
1
Views
2K
Replies
4
Views
3K
Replies
3
Views
9K
Replies
5
Views
5K
Replies
4
Views
9K
Replies
2
Views
3K
Replies
1
Views
7K
Back
Top