Graphics Programs Reference
In-Depth Information
Now like in your previous example, iterate through each row of the water
data and assign a color based on the value for the current country.
i = 0
next(waterreader)
for row in waterreader:
if row[1] in alpha3to2 and row[6]:
alpha2 = alpha3to2[row[1]].lower()
pct = int(row[6])
if pct == 100:
fill = “#08589E”
elif pct > 90:
fill = “#08589E”
elif pct > 80:
fill = “#4EB3D3”
elif pct > 70:
fill = “#7BCCC4”
elif pct > 60:
fill = “#A8DDB5”
elif pct > 50:
fill = “#CCEBC5”
else:
fill = “#EFF3FF”
print '.' + alpha2 + ' { fill: ' + fill + ' }'
i += 1
This part of the script executes the following steps:
1. Skip the header of the CSV.
2. It starts the loop to iterate over water data.
3. If there is a corresponding alpha 2 code to the alpha 3 from the CSV,
and there is data available for the country in 2008, it finds the matching
alpha 2.
4. Based on the percentage, an appropriate fill color is chosen.
5. A line of CSS is printed for each row of data.
Run generate_css.py and save the output as style.css . The first few rows of
the CSS will look like this:
.af { fill: #7BCCC4 }
.al { fill: #08589E }
Search WWH ::




Custom Search