Hey all,
I am trying to plot a scattermapbox plot. I am having a problem to include the legend. When I put “showlegend=True”, I get the value “trace0” rather than the legend I want.
The legend I want it to display is the Category column from my dataframe.
def update_map_graph(n_clicks, chosen_country, chosen_category, chosen_district):
df_sub = df[(df['Country'] == chosen_country) &
(df['Category'].isin(chosen_category)) &
(df['MainLocation'].isin(chosen_district))]
if n_clicks is None:
return dash.no_update
else:
locations = [go.Scattermapbox(
lon=df_sub['Long'],
lat=df_sub['Lat'],
mode='markers',
marker={'color': df_sub['Color'], 'size': 13, 'opacity': 0.8},
unselected={'marker': {'opacity': 0.8}},
selected={'marker': {'opacity': 0.5, 'size': 18}},
hoverinfo='text',
hovertext=df_sub['Hover']
)]
# Return figure
return {
'data': locations,
'layout': go.Layout(
autosize=True,
margin=dict(l=0,
r=0,
t=0,
b=0),
uirevision='foo',
clickmode='event+select',
hovermode='closest',
hoverdistance=2,
showlegend=False,
mapbox=dict(
accesstoken=mapbox_access_token,
bearing=0,
style='light',
center=dict(
lat=50.1109,
lon=8.6821
),
pitch=0,
zoom=5
),
)
}