Skip to main content

plot_system

plot_system(sim_data, time=None, trails=False, three_d=None, ax=None)

Plot where every body is at a single time.

Draws one marker per body at its position at the chosen time, optionally with the full trajectories drawn faintly behind. This is the snapshot counterpart to plot_orbits, which draws the whole trajectories.

If every z value in sim_data is zero, a 2D matplotlib plot is drawn. If any z value is non-zero, the work is handed to plot_system_3d, which returns an interactive plotly figure. Use three_d to force one or the other.

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
time float The time to show, in seconds from the start of the simulation. The closest recorded time step is used. The default, None, shows the last time step. None
trails bool If True, the full trajectory of each body is drawn faintly behind its marker. The default, False, shows only the markers. False
three_d bool None (the default) picks 3D only when there is motion in z. True forces a 3D plotly figure even for planar data. False forces a 2D plot, which shows the projection onto the x-y plane. None
ax matplotlib.axes.Axes Axes to draw the 2D plot on. By default a new 7 by 7 inch figure is created. Ignored when the plot is 3D. None

Returns

Name Type Description
matplotlib.axes.Axes or plotly.graph_objects.Figure The matplotlib Axes for a 2D plot, with an equal aspect ratio, axes labelled in meters and a legend of body names. A plotly Figure for a 3D plot. Either way the title gives the time shown, in seconds.

Raises

Name Type Description
ValueError If sim_data has no time column.

See Also

Notes

The 2D axis limits always cover the whole trajectories, whether or not trails is set. Snapshots of the same simulation at different times therefore share one frame and can be compared directly.

plotly is an optional dependency. If a 3D plot is called for and plotly is not installed, a warning is issued and the 2D plot is drawn instead.

Examples

The final state of a one-year simulation, with the orbits drawn behind.

import pyorbiter as orb

sim = (
    orb.create_system()
    .add_sun()
    .add_planet("Earth", parent="Sun")
    .add_planet("Mars", parent="Sun", i=0)
    .simulate(time_step=orb.seconds_per_day, duration=orb.seconds_per_year)
)
orb.plot_system(sim, trails=True)

The same system at day 100, markers only.

import pyorbiter as orb

sim = (
    orb.create_system()
    .add_sun()
    .add_planet("Earth", parent="Sun")
    .add_planet("Mars", parent="Sun", i=0)
    .simulate(time_step=orb.seconds_per_day, duration=orb.seconds_per_year)
)
orb.plot_system(sim, time=100 * orb.seconds_per_day)