After noticing high turnout in a few marginal constituencies in the election results this week, I wondered if this represented a wider trend: more people vote if the race is going to be a close one. I took the election results from 2015 (the Electoral Commission hasn’t published full 2017 results yet) and plotted turnout in each constituency across the UK as a function of the majority, calculated as the difference in votes between the two leading candidates as a fraction of the total votes cast. The result is shown below:

Surprisingly, there doesn’t appear to be much correlation in any country across the UK, and I’d welcome ideas as to why.

The plot above is made with Bokeh, a python library for producing interactive plots. You can zoom and pan the plot, hover over each data point to find out which constituency it represents, and show or hide the data for each country by clicking on the legend entry. I’m impressed with the library so far – the python code generates a javascript file and an html tag to embed into the page. After loading and processing the data, the above plot took about 10 lines of code!

One thought on “Marginal seats and turnout with Bokeh

Leave a Reply

Your email address will not be published. Required fields are marked *