diff --git a/CHANGELOG.md b/CHANGELOG.md index 898bc1bf4c..32b89c0479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased +### Fixed +- Improve `px.*_map()` auto-fitting behavior when `zoom` and `center` are not specified [[#5686](https://github.com/plotly/plotly.py/pull/5686)] + ## [7.0.0rc0] - 2026-07-29 diff --git a/plotly/express/_chart_types.py b/plotly/express/_chart_types.py index fd353d1a00..ad5f01d8b9 100644 --- a/plotly/express/_chart_types.py +++ b/plotly/express/_chart_types.py @@ -1258,7 +1258,7 @@ def scatter_map( color_continuous_midpoint=None, opacity=None, size_max=None, - zoom=8, + zoom=None, center=None, map_style=None, title=None, @@ -1296,7 +1296,7 @@ def choropleth_map( range_color=None, color_continuous_midpoint=None, opacity=None, - zoom=8, + zoom=None, center=None, map_style=None, title=None, @@ -1331,7 +1331,7 @@ def density_map( range_color=None, color_continuous_midpoint=None, opacity=None, - zoom=8, + zoom=None, center=None, map_style=None, radius=None, @@ -1369,7 +1369,7 @@ def line_map( labels=None, color_discrete_sequence=None, color_discrete_map=None, - zoom=8, + zoom=None, center=None, map_style=None, title=None, diff --git a/plotly/express/_core.py b/plotly/express/_core.py index ddc98e67aa..9516402d84 100644 --- a/plotly/express/_core.py +++ b/plotly/express/_core.py @@ -793,14 +793,8 @@ def configure_3d_axes(args, fig, orders): def configure_map(args, fig, orders): - center = args["center"] - if not center and "lat" in args and "lon" in args: - center = dict( - lat=args["data_frame"][args["lat"]].mean(), - lon=args["data_frame"][args["lon"]].mean(), - ) fig.update_maps( - center=center, + center=args["center"], zoom=args["zoom"], style=args["map_style"], ) diff --git a/plotly/express/_doc.py b/plotly/express/_doc.py index 3df6a19159..42cb991df1 100644 --- a/plotly/express/_doc.py +++ b/plotly/express/_doc.py @@ -500,7 +500,12 @@ "In `'overlay'` mode, strips are on drawn top of one another.", "In `'group'` mode, strips are placed beside each other.", ], - zoom=["int (default `8`)", "Between 0 and 20.", "Sets map zoom level."], + zoom=[ + "int (default `None`)", + "Between 0 and 20.", + "Sets initial map zoom level. Higher values are more zoomed-in.", + "If not provided, the map will select its own zoom level.", + ], orientation=[ "str, one of `'h'` for horizontal or `'v'` for vertical. ", "(default `'v'` if `x` and `y` are provided and both continuous or both categorical, ", diff --git a/tests/percy/plotly-express.py b/tests/percy/plotly-express.py index 9592b0b35d..a7bd980c32 100644 --- a/tests/percy/plotly-express.py +++ b/tests/percy/plotly-express.py @@ -386,7 +386,6 @@ size="car_hours", color_continuous_scale=px.colors.cyclical.IceFire, size_max=15, - zoom=10, ) fig.write_html(os.path.join(dir_name, "scatter_map.html"))