Go Scattermapbox with different traces like markers and bubbles/size possible?

Hello,

I have mutliple dataframes with different data which I plot using Plotly Go Scattermapbox. Everything works fine. I add the dataframes with fig.add_trace and enter also customdata in there to display it in the hover.

Now I have a new dataframe which has lat, lon, name and also some values showing me the amount of prices and I want to have a bubbles on the map indicating where the price is high or low with big or small bubbles. Is this possible to add as a additional trace on my existing map?

What I currently have is something like this:

import plotly.graph_objects as go

token = open(".mapbox_token").read() # you need your own token

fig = go.Figure(go.Scattermapbox(
    mode = "markers",
    lon = df1['lon'],
    lat = df1['lat'],
    marker = {'size': 13},
    text = df1['name']

fig.add_trace(go.Scattermapbox(
    mode = "markers",
    lon = df2['lon'],
    lat = df2['lat'],
    marker = {'size': 13},
    text = df2['name']

fig.update_layout(
    mapbox = {
        'accesstoken': token,
        'style': "streets", 'zoom': 0.7},
    showlegend = False)

fig.show()

Hi,

like the size parameter in the first example here?

Unfortunately size doesn’t work with Plotly Graph objects.

This is the linked example using plotly.graph_objects:

import plotly.graph_objects as go
import plotly.express as px             # just as data source

# get data source
df = px.data.carshare()

# create scatter
data = go.Scattermapbox(
    lat=df.centroid_lat,
    lon=df.centroid_lon,
    mode='markers',
    marker={
        'color': df.peak_hour,
        'size': df.car_hours/100
    }
)

# create figure
fig = go.Figure(data=data, layout={'mapbox':{'style': "open-street-map"}})

# show figure
fig.show()

I had to scale the values from df.car_hours due to the high values in this column.

1 Like

Thanks I will try it. But in your provided link I can’t find the code you posted.