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))])
fig.update_layout(
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(
x=[x1[k]],
y=[y1[k]],
z=[z1[k]],
mode="markers",marker=dict(color="red", size=10))],
traces=[0],name=f'frame{k}') for k in range(100)]
fig.update(frames=frames)
fig.update_layout(updatemenus=[dict(type="buttons",buttons=[dict(label="Play",method="animate",args=[None])])])
fig.write_html('Orbits.html', auto_open=True)