✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Choropleth map for Saudi Arabia

Hello. I have been trying lately to make a Choropleth map but I’ve reached a dead end by now and I need some help or suggestions. I’ve checked my GeoJSON file online and it’s working, and I’ve made IDs for the states of my country with the same ID of GeoJSON file and followed Plotly Guide, but still it has not worked yet…

I get this result, which is wrong:

This is my code on Colab (last 4 cells). Thanks and I really appreciate it.

@MahouTsukai0,
Welcome to Plotly forum!

It seems that your geojson file is corrupted. I tried with another geojson file derived from a shapefile
and with a dataframe with synthetic data I got the following map:

To restrict the map to SAU you can update the layout as follows:

fig.update_geos(center ={'lon': 45.0792, 'lat': 23.9959},
               lataxis_range= [15, 32], lonaxis_range=[33, 57])  

With the same dataframe (synthetic data), but your geojson file it was displayed a map like in your posted image.

The geojsonfile I derived from a shapefile, can be downloaded
here: https://github.com/empet/Datasets/blob/master/SAU-geo.zip

This file already has an id key.
file['features'][0]['properties'] is the dict:

{'GID_0': 'SAU',
 'NAME_0': 'Saudi Arabia',
 'GID_1': 'SAU.1_1',
 'NAME_1': '`Asir',
 'VARNAME_1': 'Asir|Aseer|Assyear',
 'NL_NAME_1': None,
 'TYPE_1': 'Emirate|Mintaqah',
 'ENGTYPE_1': 'Region',
 'CC_1': None,
 'HASC_1': 'SA.AS',
 'id': 0}

The region name is the value associated to the key ‘NAME_1’.

The list of all regions contains some longer names:

region=[]
for feat in file['features']:
    region.append(feat['properties']['NAME_1'])

and the regions are:

['Asir',
 'Al Bahah',
 'Al Hudud ash Shamaliyah',
 'Al Jawf',
 'Al Madinah',
 'Al Quassim',
 'Ar Riyad',
 'Ash Sharqiyah',
 "Ha'il",
 'Jizan',
 'Makkah',
 'Najran',
 'Tabuk']
​```

I hope it helps.
1 Like

Thanks @empet, this is an excellent explanation. I got it working now!