Skip to content
Prev Previous commit
Next Next commit
Ruff formatting
  • Loading branch information
ajlien committed Oct 22, 2025
commit bd178f62d4de56e614111670b05d095df2d20f80
36 changes: 24 additions & 12 deletions plotly/figure_factory/_hexbin_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ def _getBoundsZoomLevel(lon_min, lon_max, lat_min, lat_max, mapDim):
Source: https://stackoverflow.com/questions/6048975/google-maps-v3-how-to-calculate-the-zoom-level-for-a-given-bounds
"""

scale = (
2 # adjustment to reflect MapBox base tiles are 512x512 vs. Google's 256x256
)
scale = 2 # adjustment to reflect MapBox base tiles are 512x512 vs. Google's 256x256
WORLD_DIM = {"height": 256 * scale, "width": 256 * scale}
ZOOM_MAX = 18

Expand Down Expand Up @@ -295,7 +293,11 @@ def _compute_wgs84_hexbin(
{"x1": centers[:, 0], "x2": centers[:, 1]},
native_namespace=native_namespace,
)
.select(hexagons_ids=nw.concat_str([nw.col("x1"), nw.col("x2")], separator=","))
.select(
hexagons_ids=nw.concat_str(
[nw.col("x1"), nw.col("x2")], separator=","
)
)
.get_column("hexagons_ids")
)

Expand Down Expand Up @@ -423,7 +425,9 @@ def create_hexbin_map(
lon=df.get_column(args["lon"]).to_numpy(),
lat_range=lat_range,
lon_range=lon_range,
color=df.get_column(args["color"]).to_numpy() if args["color"] else None,
color=df.get_column(args["color"]).to_numpy()
if args["color"]
else None,
nx=nx_hexagon,
agg_func=agg_func,
min_count=min_count,
Expand All @@ -440,20 +444,25 @@ def create_hexbin_map(
)
)

agg_data_frame = nw.concat(agg_data_frame_list, how="vertical").with_columns(
color=nw.col("color").cast(nw.Int64)
)
agg_data_frame = nw.concat(
agg_data_frame_list, how="vertical"
).with_columns(color=nw.col("color").cast(nw.Int64))

if range_color is None:
range_color = [agg_data_frame["color"].min(), agg_data_frame["color"].max()]
range_color = [
agg_data_frame["color"].min(),
agg_data_frame["color"].max(),
]

fig = choropleth_map(
data_frame=agg_data_frame.to_native(),
geojson=geojson,
locations="locations",
color="color",
hover_data={"color": True, "locations": False, "frame": False},
animation_frame=("frame" if args["animation_frame"] is not None else None),
animation_frame=(
"frame" if args["animation_frame"] is not None else None
),
color_discrete_sequence=color_discrete_sequence,
color_discrete_map=color_discrete_map,
labels=labels,
Expand All @@ -474,7 +483,9 @@ def create_hexbin_map(
original_fig = scatter_map(
data_frame=(
args["data_frame"].sort(
by=args["animation_frame"], descending=False, nulls_last=True
by=args["animation_frame"],
descending=False,
nulls_last=True,
)
if args["animation_frame"] is not None
else args["data_frame"]
Expand Down Expand Up @@ -526,6 +537,7 @@ def create_hexbin_map(
),
)


def create_hexbin_mapbox(*args, **kwargs):
warnings.warn(
"create_hexbin_mapbox() is deprecated and will be removed in the next major version. "
Expand All @@ -537,4 +549,4 @@ def create_hexbin_mapbox(*args, **kwargs):
if "mapbox_style" in kwargs:
kwargs["map_style"] = kwargs.pop("mapbox_style")

return create_hexbin_map(*args, **kwargs)
return create_hexbin_map(*args, **kwargs)