NRVA
February 12, 2020, 10:48am
1
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)
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.
empet
February 12, 2020, 11:46am
2
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.
NRVA
February 12, 2020, 12:00pm
3
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?
empet
February 12, 2020, 12:44pm
4
@NRVA
mapboxt is my mapbox token.
NRVA
February 12, 2020, 12:55pm
5
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?
NRVA
February 12, 2020, 1:05pm
6
Solved it:
fig.update_geos(fitbounds=“locations”, visible=False)
1 Like
NRVA
February 12, 2020, 2:10pm
7
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?
empet
February 12, 2020, 2:13pm
8
When the county subunits do not have unique ids, you can define/associate them, to make choropleth work.
SjurK
February 26, 2020, 2:58pm
9
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.
empet
February 26, 2020, 3:12pm
10
@SjurK meanwhile this issue was fixed.