Learn how to use Dash Bio for next-gen sequencing & quality control. 🧬 Register for the Oct 27 webinar.

Scatter3d animation

I have two planetary orbits I’d like to plot. I want to show the orbits as lines and play an animation of the current position of the planets moving by showing markers on top of these lines. When I try to animate it, though, the plot is blank – why might this be?

This is my code. So far I’ve only written the marker for one planet. (I have yet to figure out how to ‘keep’ the orbit lines in the animation without those frames getting played over):

import numpy as np
import plotly.graph_objects as go

#x1 = [...] is list of x positions from first object, obtained elsewhere in the code, N=100
#y1 = [...] etc
#z1 = [...]
#x2 = [...]
#y2 = [...]
#z2 = [...]

fig = go.Figure(data=[go.Scatter3d(x=[], y=[], z=[],mode="markers",marker=dict(color="red", size=10))])
    scene = dict(
        xaxis=dict(range=[-3e8, 3e8], autorange=False),
        yaxis=dict(range=[-3e8, 3e8], autorange=False),
        zaxis=dict(range=[-3e8, 3e8], autorange=False)))
frames = [go.Frame(data=[go.Scatter3d(
                                    mode="markers",marker=dict(color="red", size=10))],
                    traces=[0],name=f'frame{k}') for k in range(100)]

fig.write_html('Orbits.html', auto_open=True)