Canada election 2008 - now results by margin of victory

This is another follow-up for this project.

I've managed to now make results that are shaded by the margin of victory. The alpha, or transparency, is a value proportion between 0 and 1. Because the margin of victory rarely goes above, say, 0.4 (40%), then we have to transform that number so that the map doesn't look like a succession of transparent polygons. To each proportion value, I crossed it with a root 8 ("** 0.125" in python). So, a 0.1 margin of victory becomes around 0.75, and 0.2 is 0.8.

Here is a part of the code that I used to customize the poly style:

if totalVotes > 0:
    prop_votes = (maxVotes - secondVotes) * 1.0 / totalVotes
    alpha = int(round(prop_votes ** 0.125 * 256)) * 0x1000000
    color += alpha
if maxVotes == secondVotes or totalVotes == 0: # votes of top two are equal
    color = 0xffffffff

Here is the result for Greater Toronto:

Greater Toronto - 2008 election results per poll

Toronto - 2008 election results per poll

Next step, balloons...



Leave a comment

Type the characters you see in the picture above.

About this Entry

This page contains a single entry by Cedric published on August 22, 2009 2:09 PM.

Google Earth - results per poll by party color was the previous entry in this blog.

Canada election 2008 - Toronto and Montreal is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.