Skip to content

Commit 8aef5df

Browse files
authored
Merge pull request #5686 from plotly/fix-bad-default-zoom-5450
Fix bad default zoom in Plotly Express map functions
2 parents be7b278 + 79d791a commit 8aef5df

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44

55
## Unreleased
66

7+
### Fixed
8+
- Improve `px.*_map()` auto-fitting behavior when `zoom` and `center` are not specified [[#5686](https://github.com/plotly/plotly.py/pull/5686)]
9+
710

811
## [7.0.0rc0] - 2026-07-29
912

plotly/express/_chart_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ def scatter_map(
12581258
color_continuous_midpoint=None,
12591259
opacity=None,
12601260
size_max=None,
1261-
zoom=8,
1261+
zoom=None,
12621262
center=None,
12631263
map_style=None,
12641264
title=None,
@@ -1296,7 +1296,7 @@ def choropleth_map(
12961296
range_color=None,
12971297
color_continuous_midpoint=None,
12981298
opacity=None,
1299-
zoom=8,
1299+
zoom=None,
13001300
center=None,
13011301
map_style=None,
13021302
title=None,
@@ -1331,7 +1331,7 @@ def density_map(
13311331
range_color=None,
13321332
color_continuous_midpoint=None,
13331333
opacity=None,
1334-
zoom=8,
1334+
zoom=None,
13351335
center=None,
13361336
map_style=None,
13371337
radius=None,
@@ -1369,7 +1369,7 @@ def line_map(
13691369
labels=None,
13701370
color_discrete_sequence=None,
13711371
color_discrete_map=None,
1372-
zoom=8,
1372+
zoom=None,
13731373
center=None,
13741374
map_style=None,
13751375
title=None,

plotly/express/_core.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,8 @@ def configure_3d_axes(args, fig, orders):
793793

794794

795795
def configure_map(args, fig, orders):
796-
center = args["center"]
797-
if not center and "lat" in args and "lon" in args:
798-
center = dict(
799-
lat=args["data_frame"][args["lat"]].mean(),
800-
lon=args["data_frame"][args["lon"]].mean(),
801-
)
802796
fig.update_maps(
803-
center=center,
797+
center=args["center"],
804798
zoom=args["zoom"],
805799
style=args["map_style"],
806800
)

plotly/express/_doc.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,12 @@
500500
"In `'overlay'` mode, strips are on drawn top of one another.",
501501
"In `'group'` mode, strips are placed beside each other.",
502502
],
503-
zoom=["int (default `8`)", "Between 0 and 20.", "Sets map zoom level."],
503+
zoom=[
504+
"int (default `None`)",
505+
"Between 0 and 20.",
506+
"Sets initial map zoom level. Higher values are more zoomed-in.",
507+
"If not provided, the map will select its own zoom level.",
508+
],
504509
orientation=[
505510
"str, one of `'h'` for horizontal or `'v'` for vertical. ",
506511
"(default `'v'` if `x` and `y` are provided and both continuous or both categorical, ",

tests/percy/plotly-express.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@
386386
size="car_hours",
387387
color_continuous_scale=px.colors.cyclical.IceFire,
388388
size_max=15,
389-
zoom=10,
390389
)
391390
fig.write_html(os.path.join(dir_name, "scatter_map.html"))
392391

0 commit comments

Comments
 (0)