Vary the size of clusters of points according to the number of points

Hello,

Iโ€™m following the official tutorial on this page to learn how to display clusters of data points. It as simple as:

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()

However, it could be really nice if each individual point was the same size (in cases where each row of the DataFrame is equally important) and if the size of the clusters of data points varied according to the number of data points inside the clusters. For example, when we would zoom in to see each data point individually, they would all be exactly the same size. However, when we would zoom out to see clusters, then each of them would be bigger according to the number written in the center of the circle.

How can it be done?

I think that Iโ€™m not able to edit my post twice, so here are some complementary information:

  • To see an example of the output that I wish, you can refer to the picture below (which was made using QGIS and other data, but we can clearly notice that each cluster of circles has a size according to the number of data points it contains):

  • The map doesnโ€™t have to be interactive. The goal is to add it in an academic paper, so even if itโ€™s interactive I will have to screenshot it. A fixed image in which we canโ€™t move nor zoom will still do the job.

Hey, any luck with that? As a hack one could add each marker as a new trace to the figure and set its size manually, but thatโ€™s far from an elegant solution.