Is it possible to set a discrete symbol map for plotly scattermapbox. color
and color_discrete_map
can be used to assign a certain color but can the same approach be used to assign a specific symbol using a discrete map?
With below, I want to assign the symbol_dict
to the unique values in species. Both px.scattermapbox
or go.scattermapbox
are viable.
The 2nd option doesn’t return an error but it also doesn’t show any of the points.
import plotly.express as px
import pandas as pd
df = px.data.iris()
symbol_dict = {'versicolor': 'star', 'setosa': 'circle', 'virginica': 'diamond'}
smap = df["species"].map(symbol_dict)
fig = px.scatter_mapbox(
df,
lat="sepal_width",
lon="sepal_length",
#symbol="species", # set symbol to species
#symbol_map=symbol_dict, # set symbol to species
)
fig = go.Figure(go.Scattermapbox(
lat=df['sepal_width'],
lon=df['sepal_length'],
mode='markers',
marker=dict(symbol = smap)
)
)
fig.update_layout(mapbox_style = "carto-positron")
fig.update_mapboxes(zoom = 5)
fig.show()
3