[Python] Plotly chloropleth of India not showing states properly (too small)

Discussão em 'Python' iniciado por Stack, Setembro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a choropleth of India that shows railway accident data. When I try to make run it a choropleth is created, but the states of India are too small and do not reflect their real life sizes. Here is a picture of the incorrect Choropleth.

    [​IMG]
    Here is my code:

    import plotly.express as px

    fig = px.choropleth(geo_df,geojson=geojson_data,locations="st_nm",featureidkey="properties.st_nm",color='Accidents',center=dict(lat=21,lon=78))

    fig.update_geos(center=dict(lat=22, lon=80), projection_scale=8)
    fig.show()


    The dataframe "geo_df" looks like this:

    id district dt_code st_nm st_code year \
    0 None Aizawl 261 Mizoram 15 2011_c
    1 None Champhai 262 Mizoram 15 2011_c
    2 None Kolasib 263 Mizoram 15 2011_c
    3 None Lawngtlai 264 Mizoram 15 2011_c
    4 None Lunglei 265 Mizoram 15 2011_c

    geometry Accidents
    0 POLYGON ((93.04466 23.41052, 92.9468 23.51363,... 1
    1 MULTIPOLYGON (((93.04619 23.66623, 93.04466 23... 1
    2 POLYGON ((92.89633 24.39072, 92.86116 24.31374... 1
    3 POLYGON ((92.93456 22.55405, 92.9315 22.39458,... 1
    4 POLYGON ((92.67307 23.38303, 92.68989 23.32804... 1


    The geojson I'm using (geojson_data) looks like this. I can post more records if need be:

    {'type': 'FeatureCollection',
    'features': [{'id': '0',
    'type': 'Feature',
    'properties': {'id': None,
    'district': 'Aizawl',
    'dt_code': '261',
    'st_nm': 'Mizoram',
    'st_code': '15',
    'year': '2011_c',
    'Accidents': 1},
    'geometry': {'type': 'Polygon',
    'coordinates': [[[93.04466353722471, 23.41052458365152],
    [92.9467955185, 23.51363116309284],
    [92.88104044341934, 23.51913018066304],
    [92.78164323690206, 23.299169477854896],
    [92.68989196934763, 23.328039320098465],
    [92.67307090362932, 23.383029495800503],
    [92.65472065011843, 23.51775542627049],
    [92.6746000914219, 23.623611514496908],
    [92.62566608205954, 23.796830567958324],
    [92.66083740128873, 23.832574182164645],
    [92.62719526985211, 23.953552568709124],
    [92.84739831198272, 24.02641455151432],
    [92.90244907251537, 24.22162967525655],
    [92.86116100211588, 24.31373821955746],
    [92.89633232134507, 24.39072446554031],
    [93.00949221799551, 24.412720535821126],
    [93.02325490812868, 24.23400246478951],
    [92.97585008655889, 24.11577358703013],
    [93.2067574432375, 24.047035867402585],
    [93.15017749491228, 23.81057811188383],
    [93.04466353722471, 23.76521121692965],
    [93.04619272501728, 23.66622890066599],
    [93.04466353722471, 23.41052458365152]]]}},


    How do I fix this so the states are scaled correctly?

    Continue reading...

Compartilhe esta Página