Quick Sketch – Election Maps

On my to do list over the next few weeks is to pull together a set of resources that could be useful in supporting data related activities around the UK General Election.

For starters, I’ve popped up an example of using the folium Python library for plotting simple choropleth maps using geojson based Westminster Parliamentary constituency boundaries: example election maps notebook.

What I haven’t yet figured out – and don’t know if it’s possible – is how to generate qualitative/categorical maps using predefined colour maps (so eg filling boundaries using colour to represent the party of the current MP etc). If you know how to do this, please let me know via the comments…;-)

Also in the notebook is a reference to an election odds scraper I’m running over each (or at least, many…let me know if you spot any missing ones…) Parliamentary constituencies. The names associated with the constituencies don’t correspond in an exact match sense to any standard vocabularies, so on the to do list is to work out a mapping from the election odds constituency names to standard constituency identifiers. I’m thinking this could be represent a handy way of demonstrating my Westminster Constituency reconciliation service docker container….:-)


  1. Andrew Teale

    Doesn’t seem too difficult to me: I do this all the time, but all my maps are manually drawn. I assume you’ll need some sort of mapping between winning party and colour to do it.

    • Tony Hirst

      @andrew The colour mapping when generating choropleth style maps in folium is based around d3.js colour brewer sequential scales.

      When generating thematic maps based on a categorical variable (such as election prediction or outcomes by party), it would be convenient to be able to pass in a colour map as a dict that maps {‘colvar1’:color1, ‘colvar2’:color2, …, ‘colvarN’:colorN}, where for example ‘colvarN’ are party names and colorN appropriate colour map values.

      One option in the folium context may be to add support for colorbrewer qualitative scales, though it would also be useful to be able to define color maps for cases where conventional colorings are used (as for political parties, for example).

      I can’t offhand see how to do that in the folium context currently?