Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Blank choropleth map

I am trying to make a choropleth map like this but from a shape file of my own country.

I have converted shape-file to geoJSON like this:

import json

geodf = data.to_crs({'init': 'epsg:4326'})
data.to_file("geojson_norge", driver = "GeoJSON")
with open("geojson_norge") as geofile:
    j_file = json.load(geofile)

Skjermbilde 2020-02-12 kl. 11.44.54

But loading this into pc.choropleth returns blank:

I have been struggling with this map for days with no luck. Hope you can point me in the right direction.

Hi @NRVA,

I created here https://plot.ly/~empet/15238 the Norway choropleth from shapefile, and it was displayed. To see what is wrong with your data, just check your ids as it is explained in the notebook at the above link.

Thank you for replying, I have actually already checked out the notebook you made, very good job.

I had to leave out the mapbox as mapboxt was not defined (I don’t know what that is). Is that your local equivalent of the geo_scope?

@NRVA
mapboxt is my mapbox token.

ok. Thanks anyway:) super helpful

Final question, do you know how to remove the “default” background map (grey areas), so I can show only Norway?

and/or how I can zoom so the default state is zoomed in on Norway?

Solved it:
fig.update_geos(fitbounds=“locations”, visible=False)

1 Like

I did not get it to work well on level 2 (municipality). There does not seem to be a unique municipal id I can use to link my data with. Do you know a solution for this? Have you done any work on level 2 with this data?

When the county subunits do not have unique ids, you can define/associate them, to make choropleth work.

This read_geojson() workaround makes Dash display local data for me as well, thanks.

The strange thing is that outside Dash, pure python/plotly express works as expected even without copying id’s to the required place.

@SjurK meanwhile this issue was fixed.