-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Description
Here's how I create the map and add a dropdown menu with option1 and option2.
import pandas as pd
import plotly.express as px
us_cities = pd.read_csv(
'https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv'
)
fig = px.scatter_mapbox(
us_cities,
lat='lat',
lon='lon',
hover_name='City',
hover_data=['State', 'Population'],
color_discrete_sequence=['fuchsia'],
zoom=3,
)
fig.update_layout(mapbox_style='open-street-map')
fig.update_layout(margin={'r': 0, 't': 0, 'l': 0, 'b': 0})
fig.update_layout(
updatemenus=[
dict(
buttons=list(
[
{
'args': ['type', 'option1'],
'label': 'Option 1',
'method': 'restyle',
},
{
'args': ['type', 'option2'],
'label': 'Option 2',
'method': 'restyle',
},
]
),
direction='down',
x=0.075,
xanchor='right',
yanchor='bottom',
),
]
)
fig.show()
I want to have all states listed in the dropdown menu, with an option to plot all data points of all states when set to all or option1 or whatever the name is, or alternatively, to select a state and only the data points belonging to the state to be shown and the rest are deleted.
Metadata
Metadata
Assignees
Labels
No labels