Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

create_hexbin_mapbox uses *_map chart types instead of *_mapbox #5358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
emilykl merged 10 commits into plotly:main from ajlien:update-hexbin-map-no-mapbox
Oct 22, 2025
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/apidoc/plotly.figure_factory.rst
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
create_distplot
create_facet_grid
create_gantt
create_hexbin_mapbox
create_hexbin_map
create_ohlc
create_quiver
create_scatterplotmatrix
Expand Down
12 changes: 6 additions & 6 deletions doc/python/hexbin-mapbox.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import plotly.express as px
px.set_mapbox_access_token(open(".mapbox_token").read())
df = px.data.carshare()

fig = ff.create_hexbin_mapbox(
fig = ff.create_hexbin_map(
Copy link
Member

@LiamConnors LiamConnors Oct 22, 2025

Choose a reason for hiding this comment

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

We can remove the px.set_mapbox_access_token(open(".mapbox_token").read()) lines in these examples and the information about mapbox tokens in the introduction.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 9773b5

data_frame=df, lat="centroid_lat", lon="centroid_lon",
nx_hexagon=10, opacity=0.9, labels={"color": "Point Count"},
)
Expand All @@ -63,7 +63,7 @@ import plotly.express as px
px.set_mapbox_access_token(open(".mapbox_token").read())
df = px.data.carshare()

fig = ff.create_hexbin_mapbox(
fig = ff.create_hexbin_map(
data_frame=df, lat="centroid_lat", lon="centroid_lon",
nx_hexagon=10, opacity=0.5, labels={"color": "Point Count"},
min_count=1,
Expand All @@ -80,7 +80,7 @@ import plotly.express as px
px.set_mapbox_access_token(open(".mapbox_token").read())
df = px.data.carshare()

fig = ff.create_hexbin_mapbox(
fig = ff.create_hexbin_map(
data_frame=df, lat="centroid_lat", lon="centroid_lon",
nx_hexagon=10, opacity=0.5, labels={"color": "Point Count"},
min_count=1, color_continuous_scale="Viridis",
Expand All @@ -100,7 +100,7 @@ import numpy as np
px.set_mapbox_access_token(open(".mapbox_token").read())
df = px.data.carshare()

fig = ff.create_hexbin_mapbox(
fig = ff.create_hexbin_map(
data_frame=df, lat="centroid_lat", lon="centroid_lon",
nx_hexagon=10, opacity=0.9, labels={"color": "Average Peak Hour"},
color="peak_hour", agg_func=np.mean, color_continuous_scale="Icefire", range_color=[0,23]
Expand All @@ -118,7 +118,7 @@ import numpy as np
px.set_mapbox_access_token(open(".mapbox_token").read())
df = px.data.carshare()

fig = ff.create_hexbin_mapbox(
fig = ff.create_hexbin_map(
data_frame=df, lat="centroid_lat", lon="centroid_lon",
nx_hexagon=10, opacity=0.9, labels={"color": "Summed Car.Hours"},
color="car_hours", agg_func=np.sum, color_continuous_scale="Magma"
Expand Down Expand Up @@ -150,7 +150,7 @@ frame = np.concatenate([
np.ones(N, int) * i for i in range(n_frames)
])

fig = ff.create_hexbin_mapbox(
fig = ff.create_hexbin_map(
lat=lat, lon=lon, nx_hexagon=15, animation_frame=frame,
color_continuous_scale="Cividis", labels={"color": "Point Count", "frame": "Period"},
opacity=0.5, min_count=1,
Expand Down
8 changes: 4 additions & 4 deletions plotly/figure_factory/__init__.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@

if optional_imports.get_module("pandas") is not None:
from plotly.figure_factory._county_choropleth import create_choropleth
from plotly.figure_factory._hexbin_mapbox import create_hexbin_mapbox
from plotly.figure_factory._hexbin_map import create_hexbin_map
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from plotly.figure_factory._hexbin_map import create_hexbin_map
from plotly.figure_factory._hexbin_map import create_hexbin_map, create_hexbin_mapbox

else:

def create_choropleth(*args, **kwargs):
raise ImportError("Please install pandas to use `create_choropleth`")

def create_hexbin_mapbox(*args, **kwargs):
raise ImportError("Please install pandas to use `create_hexbin_mapbox`")
def create_hexbin_map(*args, **kwargs):
raise ImportError("Please install pandas to use `create_hexbin_map`")
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def create_hexbin_map(*args, **kwargs):
raise ImportError("Please install pandas to use `create_hexbin_map`")
def create_hexbin_map(*args, **kwargs):
raise ImportError("Please install pandas to use `create_hexbin_map`")
def create_hexbin_mapbox(*args, **kwargs):
raise ImportError("Please install pandas to use `create_hexbin_mapbox`")



if optional_imports.get_module("skimage") is not None:
Expand All @@ -57,7 +57,7 @@ def create_ternary_contour(*args, **kwargs):
"create_distplot",
"create_facet_grid",
"create_gantt",
"create_hexbin_mapbox",
"create_hexbin_map",
"create_ohlc",
"create_quiver",
"create_scatterplotmatrix",
Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from plotly.express._core import build_dataframe
from plotly.express._doc import make_docstring
from plotly.express._chart_types import choropleth_mapbox, scatter_mapbox
from plotly.express._chart_types import choropleth_map, scatter_map
import narwhals.stable.v1 as nw
import numpy as np
import warnings


def _project_latlon_to_wgs84(lat, lon):
Expand Down Expand Up @@ -322,7 +323,7 @@ def _hexagons_to_geojson(hexagons_lats, hexagons_lons, ids=None):
return dict(type="FeatureCollection", features=features)


def create_hexbin_mapbox(
def create_hexbin_map(
data_frame=None,
lat=None,
lon=None,
Expand All @@ -339,7 +340,7 @@ def create_hexbin_mapbox(
opacity=None,
zoom=None,
center=None,
mapbox_style=None,
map_style=None,
title=None,
template=None,
width=None,
Expand Down Expand Up @@ -444,9 +445,12 @@ def create_hexbin_mapbox(
)

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_mapbox(
fig = choropleth_map(
data_frame=agg_data_frame.to_native(),
geojson=geojson,
locations="locations",
Expand All @@ -462,18 +466,20 @@ def create_hexbin_mapbox(
opacity=opacity,
zoom=zoom,
center=center,
mapbox_style=mapbox_style,
map_style=map_style,
title=title,
template=template,
width=width,
height=height,
)

if show_original_data:
original_fig = scatter_mapbox(
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 @@ -502,8 +508,8 @@ def create_hexbin_mapbox(
return fig


create_hexbin_mapbox.__doc__ = make_docstring(
create_hexbin_mapbox,
create_hexbin_map.__doc__ = make_docstring(
create_hexbin_map,
override_dict=dict(
nx_hexagon=["int", "Number of hexagons (horizontally) to be created"],
agg_func=[
Expand All @@ -521,6 +527,20 @@ def create_hexbin_mapbox(
"bool",
"Whether to show the original data on top of the hexbin aggregation.",
],
original_data_marker=["dict", "Scattermapbox marker options."],
original_data_marker=["dict", "Scattermap marker options."],
),
)


def create_hexbin_mapbox(*args, **kwargs):
warnings.warn(
"create_hexbin_mapbox() is deprecated and will be removed in the next major version. "
+ "Please use create_hexbin_map() instead. "
+ "Learn more at: https://plotly.com/python/mapbox-to-maplibre/",
stacklevel=2,
category=DeprecationWarning,
)
if "mapbox_style" in kwargs:
kwargs["map_style"] = kwargs.pop("mapbox_style")

return create_hexbin_map(*args, **kwargs)
20 changes: 10 additions & 10 deletions tests/test_optional/test_figure_factory/test_figure_factory.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4228,7 +4228,7 @@ def test_aggregation(self):
lon = [1, 2, 3, 3, 0, 4, 5, 0, 5, 3, 1, 5, 4, 0, 1, 2, 5]
color = np.ones(len(lat))

fig1 = ff.create_hexbin_mapbox(lat=lat, lon=lon, nx_hexagon=1)
fig1 = ff.create_hexbin_map(lat=lat, lon=lon, nx_hexagon=1)

actual_geojson = {
"type": "FeatureCollection",
Expand Down Expand Up @@ -4331,7 +4331,7 @@ def test_aggregation(self):
self.compare_dict_values(fig1.data[0].geojson, actual_geojson)
assert np.array_equal(fig1.data[0].z, actual_agg)

fig2 = ff.create_hexbin_mapbox(
fig2 = ff.create_hexbin_map(
lat=lat,
lon=lon,
nx_hexagon=1,
Expand All @@ -4341,7 +4341,7 @@ def test_aggregation(self):

assert np.array_equal(fig2.data[0].z, np.ones(5))

fig3 = ff.create_hexbin_mapbox(
fig3 = ff.create_hexbin_map(
lat=np.random.randn(1000),
lon=np.random.randn(1000),
nx_hexagon=20,
Expand All @@ -4364,8 +4364,8 @@ def test_build_dataframe(self):
columns=["Latitude", "Longitude", "Metric", "Frame"],
)

fig1 = ff.create_hexbin_mapbox(lat=lat, lon=lon, nx_hexagon=nx_hexagon)
fig2 = ff.create_hexbin_mapbox(
fig1 = ff.create_hexbin_map(lat=lat, lon=lon, nx_hexagon=nx_hexagon)
fig2 = ff.create_hexbin_map(
data_frame=df, lat="Latitude", lon="Longitude", nx_hexagon=nx_hexagon
)

Expand All @@ -4375,22 +4375,22 @@ def test_build_dataframe(self):
fig1.to_plotly_json()["data"][0], fig2.to_plotly_json()["data"][0]
)

fig3 = ff.create_hexbin_mapbox(
fig3 = ff.create_hexbin_map(
lat=lat,
lon=lon,
nx_hexagon=nx_hexagon,
color=color,
agg_func=np.sum,
min_count=0,
)
fig4 = ff.create_hexbin_mapbox(
fig4 = ff.create_hexbin_map(
lat=lat,
lon=lon,
nx_hexagon=nx_hexagon,
color=color,
agg_func=np.sum,
)
fig5 = ff.create_hexbin_mapbox(
fig5 = ff.create_hexbin_map(
data_frame=df,
lat="Latitude",
lon="Longitude",
Expand All @@ -4406,7 +4406,7 @@ def test_build_dataframe(self):
fig4.to_plotly_json()["data"][0], fig5.to_plotly_json()["data"][0]
)

fig6 = ff.create_hexbin_mapbox(
fig6 = ff.create_hexbin_map(
data_frame=df,
lat="Latitude",
lon="Longitude",
Expand All @@ -4416,7 +4416,7 @@ def test_build_dataframe(self):
animation_frame="Frame",
)

fig7 = ff.create_hexbin_mapbox(
fig7 = ff.create_hexbin_map(
lat=lat,
lon=lon,
nx_hexagon=nx_hexagon,
Expand Down

AltStyle によって変換されたページ (->オリジナル) /