I’ve been trying to get an orthographic globe to automatically rotate longitudinally, but am struggling severely. I found this topic, but the replies are not very helpful as they don’t explain how to form the frames or where to place them. I tried a few different possibilities based on other threads and example code on plotly, but nothing worked.
I finally tried creating a slider control the globe’s spin longitudinally thinking that I could somehow make the slider “Play” through the longitude slider. The screenshot below is what I currently have.
However, I can’t get the play button to actually make the slider move. I’ve tried creating frames, slider steps, and more. I’ve reviewed every plotly resource even tangentially related to this topic and have no succeeded. Clearly I am not understanding something critical in how to do this. Any assistance would be greatly appreciated.
Current code is below:
import plotly.graph_objects as go
from plotly.offline import iplot
import pandas as pd
import numpy as np
if __name__ == "__main__":
df = pd.read_csv("merge_v2.csv")
sliders = []
frames = []
lon_range = np.arange(-180, 180, 2)
sliders.append(
dict(
active=0,
currentvalue={"prefix": "Longitude: "},
pad={"t": 0},
steps=[{
'method': 'relayout',
'label': str(i),
'args': ['geo.projection.rotation.lon', i]} for i in lon_range]
)
)
# for i in lon_range:
# frame = go.Frame(data=[go.Scattergeo(lon=['geo.projection.rotation.lon', i])], name=str(i))
# frames.append(frame)
fig = go.Figure(
data=go.Scattergeo(
lon=df['Longitude'],
lat=df['Latitude'],
mode='markers',
marker_color=df['Staff Required']),
# frames=frames
)
fig.update_layout(
title='Most trafficked US airports<br>(Hover for airport names)',
geo=go.layout.Geo(
projection_type='orthographic',
showland=True,
showcountries=True,
landcolor='rgb(243, 243, 243)',
countrycolor='rgb(204, 204, 204)'
),
sliders=sliders,
updatemenus=[dict(type='buttons',
showactive=True,
y=1,
x=0.8,
xanchor='left',
yanchor='bottom',
pad=dict(t=45, r=10),
buttons=[dict(label='Play',
method='animate',
args=[None, dict(frame=dict(duration=50, redraw=False),
transition=dict(duration=0),
fromcurrent=True,
mode='immediate'
)]
)
]
)
]
)
fig.show()
print(fig)