Animating plots#
Animate a wave#
Start with a parameter that no preceding cell assigns. The animation directive supplies its changing value to the plot.
plot(sin(x-T))
// @animate(T,0,2*pi,8s)
// @config(viewport.autoFit=false, viewport.x.min=-pi, viewport.x.max=pi, viewport.y.min=-1.2, viewport.y.max=1.2)Interactive examples could not load. You can still copy the expressions.
T moves from 0 to 2*pi over eight seconds. Open the plot's settings, select Animation, then press Play T to run it. Use Pause to inspect one moment.
Editing the expression changes what is drawn. Editing the directive changes the track.
Syntax, duration, and modes#
The expanded form is // @animate(T, min, max, duration, mode), and named arguments are supported too. The compact @animate(T) uses min=0, max=10, duration=4s, mode=loop, and speed=1. Bounds can be expressions such as 2*pi.
| Mode | Behavior |
|---|---|
loop |
Repeat from the beginning after reaching the end |
bounce |
Reverse direction at each end |
once |
Run through the range once |
Use a duration unit that completion offers, such as 4s or 500ms. Speed scales the playback rate, so a speed of 2 plays twice as fast. A zero or invalid duration, or invalid bounds, does not give a useful track, so correct the warnings before playing.
Playback and timeline controls#
The plot transport provides Play and Pause plus a phase slider. Drag the slider to scrub. Step Back and Step Forward move in small phase increments, which is inspection control rather than a saved frame sequence. To restart, pause, scrub to the beginning, then press Play.
Open the animation settings to inspect the parameter, min, max, duration, mode, and speed. You can add and remove tracks there, and each track has its own play, pause, scrub, and stepping controls.
A field defined by a directive can be locked until you edit or remove that source value, or explicitly unlock it. The global Play and Pause transport controls the shared clock, while the per-track controls affect one track.
Multiple independent tracks#
Repeat @animate with different parameter names. Each track can have its own range, duration, and mode.
plot([[0,0],[2,0],[1,2]],{showPoints:false,connectPoints:true,closed:true,fill:true,rotation:T,scale:S})
// @animate(T,0,2*pi,8s)
// @animate(S,0.8,1.2,3s,bounce)
// @config(viewport.autoFit=false, viewport.lockAspect=true, viewport.x.min=-3, viewport.x.max=3, viewport.y.min=-3, viewport.y.max=3)Interactive examples could not load. You can still copy the expressions.
In this example T rotates while S changes scale. Reusing one parameter across several series synchronizes them, so give independent timelines different names.
Moving points and changing domains#
point(x,y) inside a plot can use the same parameter as a curve. An animated tMax reveals a parametric path gradually. Numeric shape fields such as rotation, scale, and translation can reference animation variables.
Viewport bounds can animate too. See the moving-window recipe. Curve animation and viewport animation are different things: one changes the data, the other changes what part of it is visible.
Sliders, scope, and persistence#
Animation uses transient parameter values. Do not expect each frame to save a new local variable assignment or a note version.
Avoid driving the same name with a preceding assignment, a slider, and an animation track all at once. Use a slider for one coefficient and a separate animation parameter for time.
Ordinary dependent cells can react through the app's normal evaluation rules, but prefer plot-local time parameters for smooth playback. A fixed viewport stops auto-fit from visibly changing the axes on every frame.
Render modes and fullscreen#
Static means reduced plot interaction, not a different series formula. Live animation controls depend on the result surface, so use Interactive for the complete exploration workflow.
Fullscreen uses the plot's resolved settings and its live parameters, and leaving fullscreen returns you to the note.
There is no promised built-in GIF or video exporter. Use the platform's recording tools if you need a recording. Changes made in embedded documentation are temporary, and Reset restores the source and the track state.