GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix bad default zoom in Plotly Express map functions by emilykl · Pull Request #5686 · plotly/plotly.py

Conversation

@emilykl

@emilykl emilykl commented Jul 29, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Link to issue

Closes #5450

Description of change

  • Remove hard-coded default zoom of 8 from px.scatter_map(), px.line_map(), px.density_map() and px.choropleth_map() functions
    • 8 is a very high zoom level and not appropriate for most circumstances
  • Remove Plotly Express code which computes a center based on the data. This is no longer needed now that plotly.js automatically computes zoom and center by default
    • Note: auto-fit for choropleth is not yet supported by plotly.js, but it didn't work in Plotly Express either since px.choropleth_map() has no lat or lon arguments
  • Remove zoom argument from px.scatter_map() Percy test to visually verify auto-fit behavior

Demo

The following screenshots show the plots produced without passing any center or zoom settings to the px function.

Before After
scatter-before scatter-after
line-before line-after
density-before density-after
choropleth-before choropleth-after

Code:

Details
import json
from urllib.request import urlopen

import pandas as pd
import plotly.express as px

# px.scatter_map()
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")
fig.update_layout(
    title_text="px.scatter_map()",
    title_font_size=18,
    margin={"r": 0, "t": 35, "l": 0, "b": 0},
    width=800,
    height=400,
)
fig.show()

# px.line_map()
us_cities = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv"
)
us_cities = us_cities.query("State in ['New York', 'Ohio']")
fig = px.line_map(us_cities, lat="lat", lon="lon", color="State")
fig.update_layout(
    title_text="px.line_map()",
    title_font_size=18,
    margin={"r": 0, "t": 35, "l": 0, "b": 0},
    width=800,
    height=400,
)
fig.show()

# px.density_map()
df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/earthquakes-23k.csv"
)
df = df[:10]
fig = px.density_map(
    df,
    lat="Latitude",
    lon="Longitude",
    z="Magnitude",
    radius=10,
    map_style="open-street-map",
)
fig.update_layout(
    title_text="px.density_map()",
    title_font_size=18,
    margin={"r": 0, "t": 35, "l": 0, "b": 0},
    width=800,
    height=400,
)
fig.show()

# px.choropleth_map()
with urlopen(
    "https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json"
) as response:
    counties = json.load(response)
df = pd.read_csv(
    "https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
    dtype={"fips": str},
)

fig = px.choropleth_map(
    df,
    geojson=counties,
    locations="fips",
    color="unemp",
    color_continuous_scale="Viridis",
    range_color=(0, 12),
    map_style="carto-positron",
    opacity=0.5,
    labels={"unemp": "unemployment rate"},
)
fig.update_layout(
    title_text="px.choropleth_map()",
    title_font_size=18,
    margin={"r": 0, "t": 35, "l": 0, "b": 0},
    width=800,
    height=400,
)
fig.show()

Testing strategy

  • Removed explicit zoom from px.scatter_map() Percy test so that any changes in scattermap fitting behavior will be captured
  • Percy tests for px.line_map() and px.density_map() already don't pass explicit center or zoom

To test locally: Run the code snippet above

Guidelines

  • I have reviewed the pull request guidelines and the Code of Conduct and confirm that this PR follows them.
  • I have added an entry to the changelog if needed (not required for documentation PRs).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
emilykl added 2 commits July 29, 2026 18:50
@emilykl
Remove auto-center behavior and hard-coded default zoom from px *_map…
d634d59
…() functions (now handled in plotly.js).

Note: choropleth map auto-centering is not yet supported in plotly.js, but the default plotly.js zoom of 1 is still better
than an arbitrary zoom of 8.
@emilykl
remove hard-coded zoom from px.scatter_map() Percy test, to visually …
9ac02ce
…test auto-fit behavior
@emilykl emilykl changed the title Fix bad default zoom 5450 Fix bad default zoom in Plotly Express map functions Jul 29, 2026
@emilykl
emilykl requested a review from camdecoster July 29, 2026 23:37
@emilykl
update changelog
0e495c0
camdecoster
camdecoster approved these changes Jul 30, 2026
View reviewed changes

@camdecoster camdecoster left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Could you update the zoom docstring in plotly/express/_doc.py? It still says the default is 8.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@emilykl

emilykl commented Jul 30, 2026

Copy link
Copy Markdown
Contributor Author

Looks good. Could you update the zoom docstring in plotly/express/_doc.py? It still says the default is 8.

Good catch, will do.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@emilykl
update zoom docstring
79d791a
@emilykl
emilykl force-pushed the fix-bad-default-zoom-5450 branch from 57a7e55 to 79d791a Compare July 30, 2026 16:33
@emilykl
emilykl merged commit 8aef5df into v7.0 Jul 30, 2026
22 of 23 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@emilykl
emilykl deleted the fix-bad-default-zoom-5450 branch July 30, 2026 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@camdecoster camdecoster camdecoster approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@emilykl @camdecoster
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.