How to customize markers in scatter_mapbox?

Hello,

I’m looking at the basic example for px.scatter_mapbox.

This is the provided code snippet:

import plotly.express as px
px.set_mapbox_access_token(open(".mapbox_token").read())
df = px.data.carshare()
fig = px.scatter_mapbox(df, lat="centroid_lat", lon="centroid_lon",     color="peak_hour", size="car_hours",
                  color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, zoom=10)
fig.show()

Would it be possible to modify the markers by setting outline width and color?

I tried the following but with no success:

fig.update_traces(
    marker=dict(
        line=dict(width=2, color='DarkSlateGrey'), # doesn't work
    )
)

Hi @sislvacl ,

I think the marker symbols are different to the ones used in go.Scatter(), the help refers to these symbols: Maki Icons | By Mapbox

There is a example in the docs however, which I adapted:

import plotly.graph_objects as go
import plotly.express as px
import pandas as pd

df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv"
)
fig = px.scatter_mapbox(
    df,
    lat="lat",
    lon="long",
    zoom=3,
    mapbox_style="open-street-map",
    )
    
fig.update_traces(
    marker=go.scattermapbox.Marker(
            size=14,
            color='rgb(0, 0, 255)',
            opacity=1.0
        )
    )
    
fig.add_trace(
    go.Scattermapbox(
        lat=df.lat,
        lon=df.long,
        mode='markers',
        marker=go.scattermapbox.Marker(
            size=8,
            color='rgb(255, 0, 0)',
            opacity=1.0
        ),
        hoverinfo='none'
    )
)

Basically you are plotting the same data twice with different marker sizes (and colors) to obtain the visual effect of a line.

Here the original example:

Example
import plotly.graph_objects as go
import pandas as pd

mapbox_access_token = open(".mapbox_token").read()

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/Nuclear%20Waste%20Sites%20on%20American%20Campuses.csv')
site_lat = df.lat
site_lon = df.lon
locations_name = df.text

fig = go.Figure()

fig.add_trace(go.Scattermapbox(
        lat=site_lat,
        lon=site_lon,
        mode='markers',
        marker=go.scattermapbox.Marker(
            size=17,
            color='rgb(255, 0, 0)',
            opacity=0.7
        ),
        text=locations_name,
        hoverinfo='text'
    ))

fig.add_trace(go.Scattermapbox(
        lat=site_lat,
        lon=site_lon,
        mode='markers',
        marker=go.scattermapbox.Marker(
            size=8,
            color='rgb(242, 177, 172)',
            opacity=0.7
        ),
        hoverinfo='none'
    ))

fig.update_layout(
    title='Nuclear Waste Sites on Campus',
    autosize=True,
    hovermode='closest',
    showlegend=False,
    mapbox=dict(
        accesstoken=mapbox_access_token,
        bearing=0,
        center=dict(
            lat=38,
            lon=-94
        ),
        pitch=0,
        zoom=3,
        style='light'
    ),
)

fig.show()