Question: Animated scattergeo map with slider, slider doesn't move when animation is played?

I am trying to make an animated geoscatter plot, with a slider. Kind of like the example here (Intro to animations in Python), but with go.Scattergeo(). I am running into the following problems, and I am hoping someone can help guide me.

  1. when I click play, the animation renders, but the slider doesn’t move. Why?
  2. If I use data = scatterplots[0] for the initial -default data, the frames stop rendering. which means I have to pass all of the data to be on the plot as default, which is undesirable since this will be a time lapse animation.

Thanks in advance for all the help.

DATA:

coords_dict = {0: [[38.963745, 37.2231663], [35.243322, 38.9224119]],
 1: [[-8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   -24.3570767,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   25.7372608,
   31.046051,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   34.5337527,
   34.5337527,
   34.80207499999999,
   33.223191,
   34.0757336],
  [34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   19.5687103,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   32.6077347,
   34.851612,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   43.483738,
   43.483738,
   38.996815,
   43.679291,
   37.9784585]],
 2: [[-8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   -8.783195,
   1.957709,
   26.820553,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   26.0197776,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   45.4506875,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   38.7945952,
   25.03764,
   25.03764,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   34.047863,
   43.5851814,
   39.2009126,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   35.86166,
   39.904211,
   38.0359899,
   38.0359899,
   34.7657099,
   34.7657099,
   30.5453899,
   34.2648599,
   29.720415,
   36.519334,
   28.7040592,
   38.7945952,
   38.7945952,
   34.5531284,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   26.820553,
   25.7372608,
   25.6872431,
   26.820553,
   24.083333,
   24.083333,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.5259614,
   54.65837269999999,
   54.65837269999999,
   54.65837269999999,
   41.8101472,
   41.8101472,
   41.8101472,
   41.2745004,
   41.2745004,
   41.2745004,
   41.2745004,
   41.2745004,
   41.2745004,
   41.2745004,
   41.2745004,
   41.2745004,
   46.2021848,
   46.2021848,
   46.2021848,
   46.2021848,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   39.074208,
   38.6043984,
   38.6043984,
   38.6043984,
   36.33761965,
   38.09556411145435,
   39.074208,
   39.074208,
   39.074208,
   37.349722,
   39.6102887,
   39.6102887,
   38.5115496,
   29.0587757,
   20.593684,
   33.223191,
   33.223191,
   33.223191,
   33.223191,
   33.223191,
   33.223191,
   33.223191,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.768319,
   41.87194,
   41.87194,
   41.87194,
   41.87194,
   41.87194,
   53.02431240000001,
   26.1420358,
   40.1208752,
   37.5999938,
   30.585164,
   30.585164,
   30.585164,
   30.585164,
   36.4103395,
   34.0757336,
   34.0757336,
   34.0757336,
   34.0757336,
   34.0757336,
   34.5531284,
   34.0757336,
   23.634501,
   23.634501,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   29.2985278,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   31.046051,
   34.5337527,
   34.5337527,
   34.5337527,
   34.5337527,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   36.4103395,
   36.4103395,
   36.4103395,
   36.4103395,
   -22.7359095,
   -25.274398,
   30.375321,
   31.952162,
   31.952162,
   31.1471305,
   31.230416,
   31.230416,
   33.223191,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   34.80207499999999,
   38.963745,
   38.963745,
   38.963745,
   38.963745,
   38.963745,
   38.963745,
   38.963745,
   34.047863],
  [34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   34.508523,
   37.2972044,
   30.802498,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   32.277834,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   68.8319005,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   106.5348379,
   76.4563087,
   76.4563087,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   100.6196553,
   45.0,
   45.4082269,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   104.195397,
   116.407395,
   114.46979,
   114.46979,
   113.75322,
   113.75322,
   114.34234,
   108.95424,
   112.650141,
   116.610556,
   77.10249019999999,
   106.5348379,
   106.5348379,
   18.0480105,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   30.802498,
   32.6077347,
   32.6396357,
   30.802498,
   32.883333,
   32.883333,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   15.2551187,
   -5.707144700000001,
   -5.707144700000001,
   -5.707144700000001,
   21.0937311,
   21.0937311,
   21.0937311,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   -1.2121322,
   1.2643875,
   1.2643875,
   1.2643875,
   1.2643875,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   21.824312,
   22.7152131,
   22.7152131,
   22.7152131,
   27.17470585,
   25.65031695609477,
   21.824312,
   21.824312,
   21.824312,
   22.352222,
   22.047637,
   22.047637,
   21.5706786,
   76.085601,
   78.96288,
   43.679291,
   43.679291,
   43.679291,
   43.679291,
   43.679291,
   43.679291,
   43.679291,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   35.21371,
   12.56738,
   12.56738,
   12.56738,
   12.56738,
   12.56738,
   -2.196684,
   -81.7948103,
   9.0128926,
   14.0153557,
   36.238414,
   36.238414,
   36.238414,
   36.238414,
   44.38719529999999,
   37.9784585,
   37.9784585,
   37.9784585,
   37.9784585,
   37.9784585,
   18.0480105,
   37.9784585,
   -102.552784,
   -102.552784,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   42.5509603,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   34.851612,
   43.483738,
   43.483738,
   43.483738,
   43.483738,
   38.996815,
   38.996815,
   38.996815,
   44.38719529999999,
   44.38719529999999,
   44.38719529999999,
   44.38719529999999,
   140.0187653,
   133.775136,
   69.34511599999999,
   35.233154,
   35.233154,
   75.34121789999999,
   121.473701,
   121.473701,
   43.679291,
   38.996815,
   38.996815,
   38.996815,
   38.996815,
   38.996815,
   38.996815,
   38.996815,
   38.996815,
   35.243322,
   35.243322,
   35.243322,
   35.243322,
   35.243322,
   35.243322,
   35.243322,
   100.6196553]]}

PLOTLY/PYTHON CODE:

import plotly.graph_objects as go

scattergeo_plots = []
for k,v in coords_dict.items():
    scattergeo_obj = go.Scattergeo(lat = v[0],lon = v[1])
    scattergeo_plots.append(scattergeo_obj)
scattergeo_plots


#slider and step configuration
steps = []
for i in range(len(scattergeo_plots)):
    
    step = dict(
        method='update',
        args=[{'visible': [False] * len(scattergeo_plots)}, {'title': f'Time'}]
    )
    step['args'][0]['visible'][i] = True
    steps.append(step)

# Create the slider configuration
sliders = [{
    'active': 0,
    'currentvalue': {'prefix': 'Trace: '},
    'pad': {'t': 50},
    'steps': steps
}]


# Create figure

# For animated figure, I need 3 things - data, layout and frames. sliders are a part of layout
fig = go.Figure(
    data=scattergeo_plots,
    layout=go.Layout(
        title="Scattergeo Animation",
        showlegend=False,
        geo=dict(
            projection_type="natural earth"  # Set the desired projection type
        ),
        updatemenus=[dict(
            type="buttons",
            buttons=[dict(label="Play",
                          method="animate",
                          args=[None, {"frame": {"duration": 500, "redraw": True},
                                       "fromcurrent": True, "transition": {"duration": 0}}]),
                     dict(label="Pause",
                          method="animate",
                          args=[[None], {"frame": {"duration": 0, "redraw": False}, "mode": "immediate",
                                         "transition": {"duration": 0}}])]
        )],
        sliders = sliders
    ),
    frames=[go.Frame(data=[plot_obj]) for plot_obj in scattergeo_plots]
)

# Show the figure
fig.show()

maybe try: method='animate',

@allsyntax

Thank you for your response, I appreciate it.

I tried that initially and surprisingly the result is completely incorrect if I use ‘animate’. In that case, the animation doesn’t work correctly both with play button and the slider. Wrong data is shown at a given step. I’ve shared the data and the code above, you can give it a try.

thanks in advance for your help.

I believe the args might be different. use 'animate' with:

for i in range(len(scattergeo_plots)):
    step = dict(
        method='animate',
        args=[[i]], 
        label=str(i)
    )
    steps.append(step)

Sorry, I changed the step configuration as you suggested, but that doesn’t help. I am not sure how this will work, because currently I update the visible flag to true/False depending on the step location on the slider. Can you explain what this does?

args=[[i]]

specifies frame from the loop that should be displayed when the slider moved to the step.

Could be that this feature isn’t compatible with the scattergeo plots. Maybe someone with some more experience with them can confirm or provide some guidance.