Scatter Plots on Mapbox Cluster Map CODE IS NOT UPDATED #scattermapbox #mapbox #token

Hi everyone!

It seems that this code :

import plotly.express as px
import pandas as pd

px.set_mapbox_access_token(open(“.mapbox_token”).read())
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”, size=“cnt”, zoom=3)
fig.update_traces(cluster=dict(enabled=True))
fig.show()

Is not updated to Plotly version 5, it was made with Plotly.jSv2.
Does anyone know how I can perform this map correctly in python? I have my own mapbox token but I couldn’t figure out how this code is supposed to work

Thanks in advance :slight_smile:
Best!

Hi @Alan_mg298
:wave: Welcome to the community.

Try to remove the set_mapbox_access_token line of code. And add the accesstoken line of code.
Here’s the full example. Make sure to insert your own token at the end.

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", size="cnt", zoom=3)
fig.update_traces(cluster=dict(enabled=True))
fig.update_layout(mapbox = {'accesstoken': "my-mapbox-token-here"})
fig.show()

Thanks! But I got this error :confused: :

Did you mean “lat”?

Bad property path:
cluster
^^^^^^^

Hi @Alan_mg298
The code above still works for me when I insert my mapbox token. Did you copy paste the exact code?

Hey Adam

Sure thing, I’m using the same code

The error message is very long tho, the last sentence is still on the cluster property

Did you mean “lat”?

Bad property path:
cluster
^^^^^^^

so weird that we’re getting different results with the same code. What version of Plotly are you using?

I’m using Plotly 5.21.0

I’m using Plotly 5.9.0

I see. Well, I think that if you install Plotly==5.21.0 it should work.

1 Like

TY so much! That actually works :partying_face: