[Python] plotly python: go.chloroplethmap location auto zoom

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I cannot seem to find a similar question here on SO, but please direct me there if such a question already exists.

    I have a function that plots values on a map, as below. The graph works fine. Note that it is the go.Chloroplethmap() function, as opposed to the go.Chloropleth or other similar functions with Plotly Express. I know that there was a recent transition within Plotly for the map features, which may be why it's so difficult to find an answer.

    I would like the map to auto-zoom to a certain location. Here is what I have tried:

    go.Choroplethmap(
    geojson=states_uts,
    locations=india['state_ut'],
    z=india[feature],
    featureidkey="properties.name",
    colorscale=px.colors.sequential.Reds,
    marker={"line": {"width": 0.001, "color": "white"}}
    )
    ).update_layout({
    "geo": {
    # "scope": "asia",
    # "center": {"lon":78.9629, "lat": 20.5937},
    # "projection_type": "mercator",
    # "fitbounds": "locations",
    }
    }).update_geos({
    # "scope": "asia",
    # "fitbounds": "locations",
    # "projection_type": "mercator",
    # "center": {"lon":78.9629, "lat": 20.5937},
    })


    None of the commented out lines was able to effectively zoom in on the region. Does anyone have a hint as to how to do so, after the recent Plotly map transition?

    Continue reading...

Compartilhe esta Página