Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting UK Districts, Postcode Areas and Regions

I am wondering if we can do similar choropleth as below with UK District, Postcode Area and Region map.

It would be great if you could show an example for UK choropleths.

Geographic shape files can be downloaded from http://martinjc.github.io/UK-GeoJSON/

state_geo = os.path.join('data', 'us-states.json')
state_unemployment = os.path.join('data', 'US_Unemployment_Oct2012.csv')
state_data = pd.read_csv(state_unemployment)

j1 = pd.read_json(state_geo)

from branca.utilities import split_six
threshold_scale = split_six(state_data['Unemployment'])

m = folium.Map(location=[48, -102], zoom_start=3)

m.choropleth(
    geo_path=state_geo,
    geo_str='choropleth',
    data=state_data,
    columns=['State', 'Unemployment'],
    key_on='feature.id',
    fill_color='YlGn',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Unemployment Rate (%)'
)

m

m.save('choropleth.html')
like image 298
BigDataScientist Avatar asked Sep 02 '25 16:09

BigDataScientist


1 Answers

This is what I did.

First, collect your data. I used www.nomisweb.co.uk to collect employment rates for the main regions:

  • North East (England)
  • North West (England)
  • Yorkshire and The Humber
  • East Midlands (England)
  • West Midlands (England)
  • East of England
  • London South East (England)
  • South West (England)
  • Wales Scotland
  • Northern Ireland

I saved this dataset as UKEmploymentData.csv. Note that you will have to change the region names to match the geo data id's.

Then I followed what you posted using the NUTS data from the ONS geoportal.

import pandas as pd
import os
import json

# read in population data
df = pd.read_csv('UKEmploymentData.csv')

import folium
from branca.utilities import split_six
state_geo = 'http://geoportal1-ons.opendata.arcgis.com/datasets/01fd6b2d7600446d8af768005992f76a_4.geojson'

m = folium.Map(location=[55, 4], zoom_start=5)
m.choropleth(
    geo_data=state_geo,
    data=df,
    columns=['region', 'Total in employment - aged 16 and over'],
    key_on='feature.properties.nuts118nm',
    fill_color='YlGn',
    fill_opacity=0.7,
    line_opacity=0.2,
    legend_name='Employment Rate (%)',
    highlight=True
)

m
like image 58
ImNotAnExpert Avatar answered Sep 05 '25 16:09

ImNotAnExpert