Hello,
i am trying to make a scatterplot on a map with different data values. I want to use buttons to change between these valuies and change colorscale (the range of the data values are different).
I tried few things. My last idea is here in the code: I update with buttons both, visibility and layout. However this does not work as intended. Maybe somone could help?
data = pd.DataFrame({
'LON': [11, 11, 12, 12],
'LAT': [47, 48, 47, 48],
'values_1': [20,50,70,90],
'values_2': [-4, 2, -5, 3],
})
fig = go.Figure()
figpx = {}
figpx[0] = px.scatter_mapbox(
data,
lat='LAT',
lon='LON',
color= 'values_1',
color_continuous_scale=px.colors.sequential.Jet,
range_color=(0,100),
)
figpx[1] = px.scatter_mapbox(
data,
lat='LAT',
lon='LON',
color= 'values_2',
color_continuous_scale=px.colors.diverging.RdYlGn,
range_color=(-10,10),
)
fig.add_traces(figpx[0].data)
fig.add_traces(figpx[1].data)
updatemenus = [ {
'buttons': [
{'label': 'values_1',
'method': 'update',
'args': [{'visible': [True, False],
'layout': figpx[0].layout}
]
},
{'label': 'values_2',
'method': 'restyle',
'args': [{'visible': [False, True],
'layout': figpx[1].layout}
]
},
],
'showactive': True,
} ]
fig.update_layout(
mapbox_style="carto-positron",
mapbox={'zoom': 5, 'center': {'lat': 48, 'lon': 11}}
)
fig.update_layout(
title = 'Data',
height=600,
margin={"r":0,"t":0,"l":0,"b":0})
fig.update_layout(updatemenus=updatemenus)
fig.show()