Skip to content
Advertisement

How to plot a Plotly Choropleth map with English local authorities using GeoJSON

I have copied the example from the Plotly guidance here. and I am able to reproduce their map of US Counties.

Now I am trying to produce a similar Choropleth map, except using English Local Authorities. I have downloaded a GeoJSON for English Lower Tier Authorities from here.. This was huge resolution and slow to load, so I’ve compressed it to a lower resolution JSON. My JSON is here: https://github.com/thomasvalentine/Choropleth/blob/main/Local_Authority_Districts_(December_2021)_GB_BFC.json

This JSON didn’t have an id property, which the guidance says is important for linking the shapefile with the dataframe, so I have iterated over the JSON and inserted ids, corresponding to my dataframe. The structure of one entry in the JSON now looks like this:

JavaScript

From what I can tell, this appears to be the same structure as the US counties example in the plotly guidance. And my dummy data looks like this:

JavaScript

I’ve copied the code from the ploty guidance and adapted some parts:

JavaScript

The code runs without errors, but when it opens in the browser, it just displays a random big yellow shape: enter image description here

Advertisement

Answer

I deployed choroplethmap_box instead of choropleth and it worked. Please refer below code:

JavaScript

And here is the Ouput: enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement