Skip to content

fitbounds="locations" parameter not working for px.choropleth_map #4262

Open

Description

@mattiatantardini

The fitbounds parameter appear not to work when used in choropleth mapbox. The only way I found to pass it to the Figure object was to use the update_geos method.

The following is a sample of the code to show the parameter used:

fig = px.choropleth_mapbox(
        df, 
        geojson=self.geojson,
        featureidkey=self.featureidkey,
        locations="location_code,
        color=self.metric,
        mapbox_style="carto-positron",
        opacity=0.4
    )
fig.update_geos(fitbounds="locations")

When calling fig.show, the plot opens to the (0,0) location in Gulf of Guinea.

Why the fitbounds parameter doesn't work on choropleth mapbox?

Activity

  1. tantardini commented on Jul 3, 2023

    @tantardini

    Another example is given by https://stackoverflow.com/q/63787612/16797805. Old question, but still "valid", in the sense that the fitbounds parameter for the choropleth mapbox plot still does not work.

  2. self-assigned this
    on Jul 11, 2024
  3. removed their assignment
    on Aug 2, 2024
  4. b-a0 commented on Sep 2, 2026

    @b-a0

    Also doesn't work on px.choropleth_map(), fig.update_geos(fitbounds="locations") doesn't work either with that choropleth

  5. camdecoster commented on Sep 2, 2026

    @camdecoster
    Contributor

    This doesn't work because choropleth_map doesn't support fitbounds yet. That still needs to be added in plotly.js, at which point it can bubble up to Plotly Express. Our docs don't seem to mention this anywhere. This is sort of covered in plotly/plotly.js#3434. There's an open PR to add support to plotly.js in plotly/plotly.js#7911.

  6. changed the title [-]`fitbounds="locations"` parameter not working for `px.choropleth_mapbox`[/-] [+]`fitbounds="locations"` parameter not working for `px.choropleth_map`[/+] on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions