Tracking dynamic markers across plots (Mathematica)

In summary, the author tried to create a slider that would control two markers on a plot, but found that it was not possible due to a limitation of the software.
  • #1
Swamp Thing
Insights Author
908
572
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
  • #2
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
  • #3
Perfect... thanks!
 
  • #4
What was it with Show that wasn’t working for you?
 
  • #5
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.
 
  • #6
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

1. What is the purpose of tracking dynamic markers across plots in Mathematica?

The purpose of tracking dynamic markers across plots in Mathematica is to visually represent the movements or changes of a variable or set of variables over time or different conditions. This can be useful in data analysis, simulation, and modeling.

2. How can I create dynamic markers in Mathematica?

To create dynamic markers in Mathematica, you can use the built-in function Dynamic and specify the desired markers using the PlotMarkers option in a Plot command. You can also customize the appearance and behavior of the markers using different options.

3. Can I track multiple markers across different plots in Mathematica?

Yes, you can track multiple markers across different plots in Mathematica by using the Dynamic function and specifying different markers for each plot. You can also use the Show command to combine multiple plots into one.

4. How can I save or export plots with dynamic markers in Mathematica?

You can save or export plots with dynamic markers in Mathematica by using the Export function and specifying the desired file format. The dynamic markers will be saved as part of the plot, and you can view or share the plot outside of Mathematica.

5. Are there any limitations to tracking dynamic markers across plots in Mathematica?

There are some limitations to tracking dynamic markers across plots in Mathematica, such as the performance may be affected if there are too many markers or if the markers are updated frequently. It is also important to carefully consider the data and variables being tracked to ensure accurate and meaningful visualizations.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
844
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
939
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
9K
Back
Top