How do I fill values for Somaliland in Plotly choropleth maps?

Viewed 149

I'm making a choropleth map in Plotly Express. My dataframe has a column called 'country' filled with ISO 3166 3 character country codes, which serves as the location argument for the figure.

I can't work out how to give values for the area called Somaliland, since it lacks international recognition, and therefore an ISO 3166 code.

I'm refering to the grey area in the horn of Africa depected here:

The grey area is what I'm referring to.

What country code can I use for this?

1 Answers

Plotly express default map only works with countries which have a ISO 3166 code. In your case, you first need to download your own geojson file, e.g. from https://geojson-maps.ash.ms/. Then you can use other codes, e.g. sov_a3 to refer to a specific country.

import plotly.express as px
import pandas as pd
import json 
  
f = open('countries.json',) 
countries = json.load(f) 

data = data = [['ETH',112079000],['SOM',15400000],['SOL',3508180]]

df = pd.DataFrame(data,columns=['sov_a3','population'])

fig = px.choropleth(df, geojson=countries, locations="sov_a3", featureidkey="properties.sov_a3", color="population")
fig.show()
Related