Skip to content

bug: Default zoom level for px.scatter_map is too high #5450

Closed

Description

@ndrezn

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.

Activity

  1. changed the title [-]Automatically set zoom and centroid for scatter tile maps[/-] [+]feat: Automatically set zoom and centroid for scatter tile maps[/+] on Jul 22, 2025
  2. emilykl commented on Dec 11, 2025

    @emilykl
    Contributor

    @ndrezn I'm moving this to the plotly.py repo since this seems to be a Plotly Express issue, not plotly.js.

    This code:

    import plotly.express as px
    import pandas as pd
    
    df = pd.DataFrame({
        "city": ["San Marino", "Chicago", "Nairobi", "Istanbul", "Trondheim"],
        "lat": [43.9360958, 41.85003, -1.28333, 41.01384, 63.43049],
        "lon": [12.4417702, -87.65005, 36.81667, 28.94966, 10.39506],
    })
    fig = px.scatter_map(
        df,
        lat="lat",
        lon="lon",
        hover_name="city",
    )
    fig.show()

    produces a map centered on the centroid but zoomed in way too far, such that none of the data is visible:
    Image

    Center and zoom info of the final plot:

    {
      center: {
          lat: 37.78942515999999,
          lon: 0.19062204000000377,
        },
        zoom: 8,
    }
    

    However, it seems the root cause is bad defaults being added by plotly.py, since the equivalent plot in plotly.js is fully zoomed out and shows all the data: Link to Codepen

    Image
  3. transferred this issue fromplotly/plotly.json Dec 11, 2025
  4. changed the title [-]feat: Automatically set zoom and centroid for scatter tile maps[/-] [+]bug: Default zoom level for `px.scatter_map` is too high[/+] on Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions