My geojson data isn't showing up in my Choropleth map results

hello guys i have some shapefiles that i want to visualize on plotly so i converted it to geojson
but for some reason i doesn’t show any thing and i don’t know why
my shapefile data is from GADM i tried a lot of countries (U.K, china, France, Qatar)
and i tried a lot of ways to convert them to geojson but none of them showed anything
the code works it doesn’t return any error but the countrys aren’t showing up on the map
i use Jupiter notebook

here is what i did
first i downloaded the shapefile from GADM https://gadm.org/download_country_v3.html

second i converted it by this website https://mapshaper.org/
and i also tried this website https://mygeodata.cloud/converter/

and finally i tried this this code

import geopandas as gpd
geodf = gpd.read_file(“path_to_your_shapefile/your_shapefile.shp”)
geodf = geodf.to_crs({‘init’: ‘epsg:4326’})
geodf.to_file(“path_to_my_geojson_file/my_geojson_file”, driver = “GeoJSON”)

all o these methods successfully created geojson file for me but when i try to visualize it
doesn’t work

this is my code

import pandas as pd
import numpy as np 
import plotly.graph_objects as go
import plotly as py
import shapefile as shp
import geopandas as gpd
import json

#in this code i tried to read Qatar shapefile and i converted it using https://mapshaper.org/

with open("json_geo_data/mygeodata_merged.json") as geofile:
    geojson_layer = json.load(geofile)

fig = go.Figure(go.Choroplethmapbox(geojson=geojson_layer, locations=df.Name, z=df.Value,
                                    colorscale="Viridis", zmin=0, zmax=1000,
                                    marker_opacity=1, marker_line_width=0))
fig.update_layout(mapbox_style="white-bg",
                  mapbox_zoom=3)
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

but it just shows white empty map

while this similarly code works just fine

from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
    counties = json.load(response)

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

import plotly.graph_objects as go

fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=df.fips, z=df.unemp,
                                    colorscale="Viridis", zmin=0, zmax=12,
                                    marker_opacity=0.5, marker_line_width=0))
fig.update_layout(mapbox_style="white-bg",
                  mapbox_zoom=3, mapbox_center = {"lat": 37.0902, "lon": -95.7129})
fig.update_layout(margin={"r":0,"t":0,"l":0,"b":0})
fig.show()

@mahmoud I suspect that the attribute id (in your geojson dict) isn’t in the right position.

Read the introduction of this notebook to learn Tips to get a right geojson type dict to define a choroplethmapbox chart https://plot.ly/~empet/15238.

1 Like
three reasons why you should buy plotly pro: support open source, get great support, host your plots and dashboards online