Hi @empet ! Here is an example with random values, still not moving with custom style, but OK with the default ones
a = ['A', 'B', 'C']
b = np.arange(2010, 2021)
c = 0
df = pd.melt(pd.DataFrame(data=c, index=b, columns=a).reset_index().rename(
columns = {'index':'year'}), id_vars = 'year', var_name = 'category').drop('value', axis=1)
df['lat'] = pd.Series(np.random.randint(34, 72, size=33))
df['lon'] = pd.Series(np.random.randint(-25, 45, size=33))
df = df.set_index(['year', 'category'])
mono_dark_1 = link to my mapbox style
###########################################################################3
index_list = df.index.levels[0].tolist()
n_frames = len(index_list)
fig = go.Figure(
go.Scattermapbox(
lat = df.xs(2015)['lat'],
lon = df.xs(2015)['lon'],
mode = 'markers',
marker = dict(
size = 4.5,
color = '#ba9c30',
opacity = 1,
),
name='x1'
)
)
frames=[]
for i in range(n_frames):
year = index_list[i]
frames.append(
go.Frame(data = [
go.Scattermapbox(
lat = df.xs(year)['lat'],
lon = df.xs(year)['lon']
)],
name = f"fr{i}",
layout = dict(mapbox = dict(style = mono_dark_1,
zoom = 2,
center = {'lon': 17, 'lat': 50}))
)
)
fig.update(frames=frames)
steps = []
for i in range(n_frames):
year = index_list[i]
step = dict(label = year,
method = 'animate',
args = [
[f"fr{i}"],
dict(mode = 'immediate',
frame = dict(duration = 1000,
redraw = True),
transition = dict(duration = 500)
)
]
)
steps.append(step)
sliders = [
dict(
transition = dict(duration = 0),
x = 0.16,
y = 0.03,
len = 0.8,
currentvalue = dict(font = {'family': 'Book Antiqua', 'size': 18, 'color': '#ffffff'},
visible = True,
xanchor = 'center',
offset = 20),
steps = steps,
active = 5,
bgcolor = '#333333',
activebgcolor='#ff0000',
font = {'family': 'Book Antiqua', 'size': 10, 'color': '#ffffff'},
ticklen = 4
)
]
play_buttons = [{
'type': 'buttons',
'showactive': False,
'bgcolor': '#333333',
'font': {'family': 'Book Antiqua', 'size': 14, 'color': '#e4e3bf'},
"direction": "left",
"pad": {"r": 10, "t": 87},
'x': 0.15,
'y': 0.1,
'buttons':
[
{
'label': 'βΆ',
'method': 'animate',
'args':
[
None,
{
'frame': {'duration': 1000, 'redraw': True},
'transition': {'duration': 500},
'fromcurrent': True,
'mode': 'immediate',
}
]
},
{
'label': 'βΌ',
'method': 'animate',
'args':
[
[None],
{
'frame': {'duration': 0, 'redraw': False},
'transition': {'duration': 0},
'mode':'immediate',
}
]
}
]
}]
fig.update_layout(sliders=sliders,
updatemenus=play_buttons,
height = 600,
width = 900,
plot_bgcolor = '#040609',
paper_bgcolor = '#040609',
mapbox = dict(
accesstoken = mapbox_token,
zoom = 2,
center = {'lon': 17, 'lat': 50},
style = mono_dark_1),
legend = {'title': None,
'orientation': 'h',
'xanchor': 'right',
'yanchor': 'middle',
'x': 1,
'y': 1.05,
'font': {'family': 'Book Antiqua', 'size': 10, 'color': '#e4e3bf'},
'itemsizing': 'constant'},
)
fig.show()