Scattergeo with sliders - all the data displayed at the beginning

I have searched for an answer to this question, and although there are a couple of similar questions, there isn’t a direct answer.

I have a scattergeo plot, that shows all the time data at the beginning, like this:

I would like it to show on the data at the first step when it first loads, however like this:

Please let me know how to set up the sliders dictionary, or the figure object to make this work. THanks!

 Define your Scattergeo plot objects
scattergeo_plots = data

steps = []

for i in range(len(data)):
    y = get_formatted_yr_range(year_ranges[i])
    step = dict(
        args=[{'visible': [False] * len(data)}, {'title': f'Time ({y})'}],
        label = y
    step['args'][0]['visible'][i] = True
#print (steps)
# Create the slider configuration
sliders = [{
    'active': 0,
    'currentvalue': {'prefix': 'Trace: '},
    'pad': {'t': 50},
    'steps': steps


# Create figure
fig = go.Figure(
    data=scattergeo_plots,  # Start with the first plot object
        title="Scattergeo Sliders",
            projection_type="natural earth"  # Set the desired projection type
        sliders = sliders

# Show the figure

Hey @ama ,

How do you define your Scattergeo ?

Just an idea;

for i in np.arange(0,5,1):
    fig.add_trace(go.Scattergeo(visible=False, ...))[0].visible = True

This way you can hide all the traces and make it visible only the first one.

And if you want to keep previous points you can try something like this:

import plotly.graph_objects as go
import numpy as np

x = [16, 11, 18, 33, 49]
y = [12, 32, 41, 33, 26]

# Create figure
fig = go.Figure(go.Scattergeo(lon=[],
                              marker=dict(color="red", size=10)

# Frames
frames = [go.Frame(data= [go.Scattergeo(lon=x[:k+1],
                   traces= [0],
                  )for k  in  range(len(x))


def frame_args(duration):
    return {
            "frame": {"duration": duration},
            "mode": "immediate",
            "fromcurrent": True,
            "transition": {"duration": duration, "easing": "linear"},

sliders = [
    {"pad": {"b": 10, "t": 60},
     "len": 0.9,
     "x": 0.1,
     "y": 0,
     "steps": [
                 {"args": [[], frame_args(0)],
                  "label": str(k),
                  "method": "animate",
                  } for k, f in enumerate(fig.frames)

                  geo=dict(projection_type="natural earth")


Thank you, this worked perfectly. I had no idea that the sliders could be setup using the frames data, like you did.

1 Like