Nick Doiron / Nov 06 2019
Remix of Python by Nextjournal
Districtr + Precinct data
import sys; sys.version.split()[0]
0.2s
Python
'3.6.8'
import json
plan = json.loads(open(districtr-plan-7e77a040.json, 'r').read())
print(plan)
0.6s
Python
def color(name):
if name in plan["assignment"]:
#['#0099cd', '#ffca5d', '#00cd99', '#ddd'][
return plan["assignment"][name]
else:
return -1 #'#eee'
print(color("Cibola County Precinct 14"))
0.4s
Python
pip install altair requests
1.8s
Bash in Python
import requests
reply = requests.get("https://mggg-states.subzero.cloud/rest/new_mexico_precincts?select=gjsimple,name10").json()
features = { "type": "FeatureCollection", "features": [] }
for row in reply:
if row["gjsimple"] == None:
# these were too small to be simplified by the function and still retain size
print(row["name10"])
else:
features["features"].append({
"type": "Feature",
"geometry": json.loads(row["gjsimple"]),
"properties": { "fill": color(row["name10"]) }
})
2.6s
Python
print(features["features"][0])
0.5s
Python
import altair as alt
print(alt.Color(0))
0.5s
Python
alt.Chart(alt.Data(values=features["features"])).mark_geoshape(
stroke='black',
fill="#aaa",
strokeWidth=1
).encode(
alt.Color("properties.fill:N")
).properties(
width=400,
height=400
)
1.7s
Python