Visualization
Visualization¶
Start with a trajectory. Give it a view, put related views together, and save the
result. The same Plot carries your data, layout and styling from a notebook
sketch to a figure or movie.
Install the drawing backend once: pip install "tsdynamics[viz]".
Make your first plot¶
import tsdynamics as ts
model = ts.systems.Lorenz(ic=[1, 1, 1])
trajectory = model.run(final_time=40, dt=0.01)
figure = ts.plot(trajectory, color="#11857A")
figure.theme("publication", foreground="#273947").font(family="sans-serif", size=12)
figure.size(6.4, 4.6)
In a notebook, put figure on the last line to display it. In a script, call
figure.show(). Save a still with figure.save("lorenz.svg") or
figure.save("lorenz.png").
The minimum is ts.plot(trajectory). Add .animate() to turn the same view
into a movie; the settings below are optional refinements.
Ask for the view you need¶
A quoted name chooses a transform; components= chooses the state variables.
You can start with an existing trajectory, a model, an array, or an analysis
result.
portrait = ts.plot(trajectory, components=["x", "z"], title="State space")
trace = ts.plot(trajectory, "time_series", components="x", title="x over time")
spectrum = ts.plot(trajectory, "psd", components="x", title="Frequency content")
ts.plot(model, final_time=40, dt=0.01) can run the model and plot it in one call.
Keeping the trajectory is useful when several views should show the same data.
The gallery shows every registered transform with real output and
its code.
Put the views together¶
Use + to put compatible data on the same axes, | for views beside one
another, and / for views above and below. Parentheses describe a nested
layout.
figure = (portrait | spectrum) / trace
figure.theme("publication").font(family="sans-serif").size(10, 7)
Two complementary views above one shared timeline. The composition guide builds this layout step by step and explains when an overlay is meaningful.
Compare and compose¶
Build a figure with overlays, rows, stacks and nested layouts. Keep each panel's own axes and units where they matter.
Give it a consistent look¶
Style the figure with a theme, a few intentional colours and readable labels. Fine-tune individual panels when needed.
Show the motion¶
Make a movie from the same plot. Reveal an orbit, link it to a time series, or play a spatial field frame by frame.
Choose a picture by the question¶
The scientific figure recipes pair copyable code with its actual output. Start with a task, then change the data or a few settings.
- Plot recorded data — arrays, timestamps and named variables
- Compare experiments — overlays, separate axes and independent styles
- Connect the evidence — state space, time series and analysis results
- Show an ensemble — readable bands for many trajectories
- Read a vector field — speeds, nullclines and trajectories
- Compare spatial fields — snapshots on one color scale
Make the same figure move¶
movie = (portrait | trace).theme("dark").size(9, 4)
movie.animate(duration=12, fps=24).trail(("time", 4), fade=True)
Both views follow the same recorded trajectory. duration controls playback
length; dt in the simulation controls how often states were recorded. Making
the movie slower reuses those samples without running the simulation again.
Visit the animation studio to compare the controls visually.
Save a movie with movie.save("lorenz.mp4") after installing FFmpeg, or
movie.save("lorenz.gif") for a short loop using Pillow.
Polish once, export when ready¶
figure.theme("publication").relabel(title="One orbit, three views")
figure[1].relabel(x="Time", y="x")
figure[1] is the lower time-series panel of this nested figure;
figure[0][0] is its upper-left portrait. Tweaks mutate the plot and return it,
so chains read in the order you apply them.
| You need | Use |
|---|---|
| A still for a paper or slide | .save("figure.svg"), .pdf or .png |
| A movie | .animate(duration=6, fps=24).save("figure.mp4") with FFmpeg installed |
| An interactive page for a supported single view or flat static layout | .save("figure.html") with the interactive extra |
| A portable plot description | .save("figure.json") |
Matplotlib renders nested layouts and movies. Interactive renderers support a smaller set of features; a capability warning explains a fallback or unsupported option. See backends and export before choosing an interactive format for a complex figure.
For a complete map of accepted inputs and the extension API, continue to transforms and primitives. For colour scales, axes and scientific presentation, see figure conventions.