Unable to change the markers style for px.scatter_mapbox

Hi, I am wondering is there a way to change the symbols of the marker from circle to pentagon or “X” or others listed in Marker Style

I am using the “open-street-map” tiles from Mapbox.

Should I use the fig.update_layout?

Hi @Muffinman and welcome to the Plotly community !

Here you can find the list of mapbox symbols - Maki Icons | By Mapbox. I don’t see a pentagon here, but there is X (cross) in the list.

You can simply set the symbol inside your go.Scattermapbox() method

go.Scattermapbox(
marker = {'size': 20, 'symbol': ["cross"]}
)
1 Like

Note that you need a mapbox token to use custom icons, even if you use non-mapbox map tiles.

2 Likes

I came across this question and I’m wondering whether there’s any way to do what the OP asked within px.scatter_mapbox? The given answer works, but only for go.Scattermapbox. I have a lot of code already written using px.scatter_mapbox and would love to just be able to style the markers that way (in my case, I’d just like to add a border around the circular markers). Thanks for any help or ideas!

1 Like

px_scatter_mapbox is just a quick way to create a figure with a go.Scattermapbox trace.

After you created your figure with plotly express, you can update it with update_layout, update_traces, etc.

to do the same as in the answer above, simply do:

fig = px.scatter_mapbox(...).update_traces(marker={"size": 20, "symbol": ["cross"]})
1 Like

Thanks - I think where I got confused is that the markers go through mapbox instead of through the normal plotly interface, so many of the options for markers are unavailable when using mapbox (whether using go or px).

So for example, “line” isn’t an option: “ValueError: Invalid property specified for object of type plotly.graph_objs.scattermapbox.Marker: ‘line’”

There is a ‘circle-stroked’ symbol that shows a circle with an outline, but then it’s not possible to change the interior color of the circle. This may just not be something that’s possible to do.

Your best bet for markers with an outline is the following workaround: create 2 traces with a different radius on the same location (and you can make one of them not have any hover interaction).

See Scatter plots on mapbox in Python for an example.