plotly.py
plotly.py copied to clipboard
Using a slider creates jitter on an animated scattermapbox
An animated scattermapbox figure with a legend sometimes shows jitter while using a slider.
import plotly.graph_objects as go
lats = [_*0.02 for _ in range(500)]
lons = [0]*500
fig = go.Figure()
fig.add_trace(go.Scattermapbox(lat=[0], lon=[0], visible="legendonly"))
fig.add_trace(go.Scattermapbox(lat=[0], lon=[0], showlegend=False))
frames = []
for lat, lon in zip(lats, lons):
frame = go.Frame(data=go.Scattermapbox(lat=[lat], lon=[lon]),
traces=[1], name=str(lat))
frames.append(frame)
fig.update(frames=frames)
fig.layout.mapbox.center = {"lat": 5, "lon": 0}
fig.layout.mapbox.style = "open-street-map"
fig.layout.mapbox.zoom = 4
def frame_args(duration):
template = {"frame": {"duration": duration},
"mode": "immediate",
"fromcurrent": True,
"transition": {"duration": 0}}
return template
def step_dict(frame):
template = {"args": [[frame.name], frame_args(0)],
"label": frame.name,
"method": "animate"}
return template
steps = [step_dict(f) for f in fig.frames]
sliders = [{"steps": steps}]
fig.update_layout(sliders=sliders)
fig.show()
https://user-images.githubusercontent.com/9297904/148424735-cb11c162-ad21-437f-afc7-55447c06d659.mov