Data Visualization/ Python(?) Questions

Data Visualization/ Python(?) Questions
0

#1

Hey campers! I’m trying to make a heat map (similar to this) using this guide but I’m having a ton of trouble and feel like I’m in way over my head. I don’t even know where to start!

Not sure if this is kosher, but does someone want to take a go at it? I will be eternally grateful and can probably provide some compensation. I have all the data in an excel sheet ready to go!

UPDATE so this is what I’ve fuddled together so far, but unfortunately the resulting svg file looks exactly the same as the base file, I don’t know what’s wrong.

### color_map.py
 
import csv
from bs4 import BeautifulSoup
 
# Read in unemployment rates
unemployment = {}
min_value = 100; max_value = 0
reader = csv.reader(open('unemployment09.csv'), delimiter=",")
for row in reader:
    try:
        full_fips = row[1] + row[2]
        rate = float( row[8].strip() )
        unemployment[full_fips] = rate
    except:
        pass
 
# Load the SVG map
svg = open('counties.svg', 'r').read()
 
# Load into Beautiful Soup
soup = BeautifulSoup(svg, selfClosingTags=['defs','sodipodi:namedview'])
 
# Find counties
paths = soup.findAll('path')
 
# Map colors
colors = ["#D7191C", "#FDAE61", "#FEE08b", "#D9EF8b", "#91CF60", "#1A9850"]
 
# County style
path_style = 'font-size:12px;fill-rule:nonzero;stroke:#FFFFFF;stroke-opacity:1;4stroke-width:0.1;stroke-miterlimit:4;stroke-dasharray:none;stroke-linecap:butt;marker-start:none;stroke-linejoin:bevel;fill:'
 
# County Color
for p in paths:
     
    if p['id'] not in ["State_Lines", "separator"]:
        try:
            rate = unemployment[p['id']]
        except:
            continue
             
         
        if rate > 10:
            color_class = 5
        elif rate > 8:
            color_class = 4
        elif rate > 6:
            color_class = 3
        elif rate > 4:
            color_class = 2
        elif rate > 2:
            color_class = 1
        else:
            color_class = 0
 
 
        color = colors[color_class]
        p['style'] = path_style + color
 
print soup.prettify()

#2

The guide you linked to has a download for the source code. Why not just use that?


#3

Where’s the data? We can continue on PM if you prefer
The guide blog looks dated in its approach and tech choices - I’d skip it and do it in d3