Skip to main content

animate_system_3d

animate_system_3d(sim_data, fps=20, duration=10, trails=False)

Animate the system over time in interactive 3D.

The 3D counterpart to animate_system. Builds a plotly 3D scene with the bodies as moving markers, Play and Pause buttons, and a time slider labelled in days. Optionally the full trajectories are drawn faintly behind. The scene can be rotated and zoomed while it plays.

Parameters

Name Type Description Default
sim_data DataFrame The output of simulate_system (pandas or polars). It must have the columns id, x, y, z (meters) and time (seconds). required
fps float Frames per second of playback. Default 20. 20
duration float Length of the animation in seconds of playback, not of simulated time. Default 10. Together with fps this sets the number of frames: about fps * duration evenly spaced time steps are drawn, and never fewer than 2. If the simulation has no more time steps than that, every time step becomes a frame. 10
trails bool If True, the full trajectory of each body is drawn faintly behind the moving markers. The default, False, shows only the markers. False

Returns

Name Type Description
plotly.graph_objects.Figure A figure with one marker per body, one animation frame per time step drawn, Play and Pause buttons and a time slider. It displays itself in a notebook. Use fig.show() in a script or fig.write_html(path) to save it.

Raises

Name Type Description
ImportError If plotly is not installed.
ValueError If sim_data has no time column.

See Also

Notes

The axis ranges are fixed to the full extent of sim_data in x, y and z, so the view does not rescale as the bodies move.

No image encoding is involved, so the figure is built quickly even for many frames. The animation is played by the browser.

Examples

Mars on an orbit tilted 25 degrees, with the orbits drawn behind. Press Play, or drag the slider.

import pyorbiter as orb

sim = (
    orb.create_system()
    .add_sun()
    .add_planet("Earth", parent="Sun")
    .add_planet("Mars", parent="Sun", i=25)
    .simulate(time_step=orb.seconds_per_day, duration=2 * orb.seconds_per_year)
)
orb.animate_system_3d(sim, fps=10, duration=4, trails=True)