Tracking dynamic markers across plots (Mathematica)

Click For Summary

Discussion Overview

The discussion revolves around implementing dynamic markers on two plots in Mathematica, where a slider controls the movement of markers on both a rectangular plot of two curves and a parametric plot. Participants explore how to achieve this without recalculating the curves when the slider is adjusted.

Discussion Character

  • Technical explanation
  • Exploratory
  • Debate/contested

Main Points Raised

  • One participant describes the goal of linking markers on two plots using a slider, while ensuring that the curves themselves remain static during interaction.
  • Another participant shares a workaround using Manipulate and Show, indicating that combining dynamic and static plots directly leads to errors.
  • A participant provides an example where a static plot works independently, but combining it with a dynamic plot results in an error, highlighting issues with variable assignment outside of Manipulate.
  • Further discussion reveals that variables assigned outside of Manipulate are treated as static, which affects their responsiveness to slider changes.

Areas of Agreement / Disagreement

Participants express different experiences with the functionality of Show and Manipulate, indicating that there is no consensus on the best approach to achieve the desired dynamic behavior without errors.

Contextual Notes

Limitations include the challenge of combining dynamic and static plots, as well as the behavior of variables assigned outside of Manipulate affecting their interaction with dynamic elements.

Swamp Thing
Insights Author
Messages
1,048
Reaction score
799
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
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   Reactions: Dale

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
9K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 4 ·
Replies
4
Views
9K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
7K