plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

feat: Automatically set zoom and centroid for scatter tile maps

Open ndrezn opened this issue 5 months ago • 0 comments

using some slightly modified examples in https://plotly.com/python/tile-scatter-maps/.

If I try (FYI need to install geopandas<1.0, note removal of the zoom setting):


import plotly.express as px
import geopandas as gpd

geo_df = gpd.read_file(gpd.datasets.get_path("naturalearth_cities"))

fig = px.scatter_map(
    geo_df,
    lat=geo_df.geometry.y,
    lon=geo_df.geometry.x,
    hover_name="name",
)
fig.show()

Then I get:

Image

Which is bad. We should set the Zoom to cover as many points as possible. Centroid on Africa seems reasonable for this example but not sure how it's determined.

Though I notice with some PX calls the centre point seems set automatically (note I removed the zoom level):

import plotly.express as px

df = px.data.carshare()
fig = px.scatter_map(
    df,
    lat="centroid_lat",
    lon="centroid_lon",
    color="peak_hour",
    size="car_hours",
    color_continuous_scale=px.colors.cyclical.IceFire,
)
fig.show()
Image

Some investigation required to understand the current behaviour.

ndrezn avatar Jul 22 '25 13:07 ndrezn