I am trying to understand Dynamic
a bit better for some classroom presentations, so I tried to make a dynamic list plot. As far as I can tell, this still requires repeatedly replotting the entire plot, but I think superceded plots can immediately be garbage collected. (Right?)
Anyway, consider the following simple example, which I believe captures my core considerations. (The Pause
just allows enough time to watch the animation.)
traj = Sin@Subdivide[0, 2 Pi, 50] (* the trajectory to plot *)
Dynamic@tmax
Dynamic[ListPlot[traj[[;; tmax]],
DataRange -> {0, 2 Pi*tmax/50},
PlotRange -> {{0, 2 Pi}, {-1, 1}}], None]
Do[FinishDynamic[]; Pause[0.01]; tmax = n, {n, 1, 51}]
- Is this basically correct as an approach to my problem of dynamic plotting?
- Does
ListAnimate
have advantages over this approach, aside from this approach a. introducing an otherwise unneeded global variable and b. not being able (afaict) to save the animation? - How can I do this inside a
DynamicModule
, to avoid introducing dynamic global variables?
Edit:
A stated in the question, a key goal here is to better understand Dynamic
and relations. For the simple example above, Animate
works just fine.
Animate[]
. $\endgroup$Dynamic
and relations. For the example,Animate
works just fine. $\endgroup$Animate
andAnimator
have the optionDisplayAllSteps
, which forces an update after each iteration. -- Generally, though, your approach is "correct." You've noted a desire to avoid the use of global variables already, and I would add that driving the animation with aDo[]
loop instead of a traditional control (as found inManipulate[]
andAnimate[]
) is likely to prove inconvenient. $\endgroup$