Skip to content

Conversation

@ajlien
Copy link
Contributor

@ajlien ajlien commented Oct 1, 2025

  • I have read through the contributing notes and understand the structure of the package. In particular, if my PR modifies code of plotly.graph_objects, my modifications concern the code generator and not the generated files.
  • I have added tests or modified existing tests.
  • For a new feature, I have added documentation examples (please see the doc checklist as well).
  • I have added a CHANGELOG entry if changing anything substantial.
  • For a new feature or a change in behavior, I have updated the relevant docstrings in the code.

Small change to remove mapbox references from figure factory's hexbin map. See #5081 in particular @danielsaaf's comment.

No docstrings or kwarg names needed to be changed, this is just a substitution.

As a side effect (and the reason I originally came across this issue), currrently if you construct a figure with create_hexbin_mapbox then add another go.Scattermap trace to it, any maki symbols in the scattermap will not render. This PR also fixes that.

@ajlien
Copy link
Contributor Author

ajlien commented Oct 1, 2025

@ajlien
Copy link
Contributor Author

ajlien commented Oct 1, 2025

Looks like they failed on the same Python code block (1), (2):

import plotly.express as px
from skimage import io
img = io.imread('https://upload.wikimedia.org/wikipedia/commons/thumb/0/00/Crab_Nebula.jpg/240px-Crab_Nebula.jpg')
fig = px.imshow(img)
fig.show()

with

HTTPError: HTTP Error 403: Forbidden

Did upload.wikimedia.org block the resource request?

@emilykl
Copy link
Contributor

emilykl commented Oct 1, 2025

Hi @ajlien , thanks for catching this, we should definitely migrate this function to use _map traces.

The doc build failure has been fixed on main, if you merge main into your branch the issue should be resolved.

We should also deprecate create_hexbin_mapbox() and rename it to create_hexbin_map(). Could you add the following changes to this branch?

  • Rename the function from create_hexbin_mapbox() to create_hexbin_map()
  • Rename the mapbox_style arg to map_style
  • Add a new create_hexbin_mapbox() function which shows a DeprecationWarning and then calls create_hexbin_map(), i.e. something like this:
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)   
  • Update plotly/figure_factory/__init__.py accordingly

I'm happy to take over this branch if you don't have the bandwidth, but if you get around to it first, go for it! Thanks again.

@ajlien
Copy link
Contributor Author

ajlien commented Oct 3, 2025 via email

@gvwilson
Copy link
Contributor

gvwilson commented Oct 7, 2025

thanks @ajlien - this looks good to me. If @emilykl approves as well, we'll get it merged.

@gvwilson gvwilson added P1 needed for current cycle community community contribution fix fixes something broken labels Oct 7, 2025
@ajlien
Copy link
Contributor Author

ajlien commented Oct 22, 2025

Hi @emilykl, just pushed commits reflecting your requested changes.

Please note that I did not update the Reference section of doc/python/hexbin-mapbox.md, as I'm not sure whether this would break existing URLs.

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

Comment on lines +38 to +39
def create_hexbin_map(*args, **kwargs):
raise ImportError("Please install pandas to use `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
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`")

@emilykl
Copy link
Contributor

emilykl commented Oct 22, 2025

Thank you @ajlien! Just need to add create_hexbin_mapbox in a few places in the figure_factory/__init__.py (see suggestions), otherwise LGTM!

df = px.data.carshare()

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

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

Copy link
Contributor

@emilykl emilykl left a comment

Choose a reason for hiding this comment

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

Thank you for the PR @ajlien ! 🚀

@emilykl emilykl merged commit 9c18a8b into plotly:main Oct 22, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community community contribution fix fixes something broken P1 needed for current cycle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants