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


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

import as px
import pandas as pd

df = pd.read_csv(
fig = px.scatter_mapbox(df, lat="lat", lon="long", size="cnt", zoom=3)

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.