Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Choropleth map dutch townships


I am trying to plot Covid-19 data on a plotly chorolepth map but the map does not show anything but an empty ploy. The geosjon file is as follows:
And a Dataframe example looks as follows:

                     Gemeente  ...  Overleden_inc100000
0    's-Gravenhage (gemeente)  ...                  0,5

Below the code I used:

import pandas as pd
from urllib.request import urlopen, Request
import json

import as px

#geodata_url1 = ''
geodata_url2 = ''

req = Request(geodata_url2, headers={'User-Agent': 'Mozilla/5.0'})

with urlopen(req) as response:
    dutch_town = json.load(response)

df = pd.read_csv('C:/Users/Dante/Desktop/Covid-19/Covid_Data/Reported COVID-19 patients - Per county from 1-Jul-2020 until 14-Jul-2020.csv', delimiter=';')


fig = px.choropleth(df, geojson=dutch_town,
                    locations= 'Gemeente', color= "Totaal_Absoluut",
                    range_color=(df["Totaal_Absoluut"].min(), df["Totaal_Absoluut"].max()),
                    labels={"Totaal_Absoluut": 'Overleden'}

fig.update_geos(fitbounds="locations", visible=False)

Hi, @DantevdH,
Most likely, your choropleth is empty because you did not pass the right information that connects the
data from your dataframe to that from the geojson.
Inspecting the geojson file, read via:

import json
with open('townships.geojson', 'r') as fp:
    jdata = json.load( fp)

it can be seen that each feature in the list jdata['features'] has a key, 'properties'.
For example



{'code': '1680',
 'name': 'Aa en Hunze',
 'regioFacet': 'tcm:106-353398-1024',
 'level': 4,
 'url': '/regioinformatie/gemeente/aa-en-hunze/'}

If each feature is uniquely identified by a 'code' (here '1680'), then your dataframe should have a
column that records these code(s) (if df['Gemeente'] contains these codes it’s OK.

Moreover in the definition:

fig = px.choropleth()


featureidkey ='properties.code'



reveals that

 |          Sets the key in GeoJSON features which is used as id to
 |          match the items included in the `locations` array. Only
 |          has an effect when `geojson` is set. Support nested
 |          property, for example "".