Introducing...mander


In [1]:
from mander import districts, metrics, utils
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline

Single District Scores

Load geojson


In [2]:
myDistrict = districts.District('test/data/CD_CA_24.geojson')

Look at shapes


In [6]:
myDistrict.gdf.plot()

Get a score


In [5]:
metrics.calculateReock(myDistrict)

Multi-district Scores

Load geojson


In [2]:
fname = 'test/data/MN_Senate_2017.geojson'

In [3]:
myDistrict = districts.District(fname)

Look at shapes


In [4]:
myDistrict.gdf.plot()


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x107750710>

Get some scores


In [5]:
reocks = metrics.calculateReock(myDistrict)

In [6]:
plt.hist(reocks)


Out[6]:
(array([  4.,   2.,   1.,   8.,  10.,  13.,   8.,  11.,   6.,   4.]),
 array([ 0.24700892,  0.28376681,  0.3205247 ,  0.35728259,  0.39404048,
         0.43079836,  0.46755625,  0.50431414,  0.54107203,  0.57782992,
         0.6145878 ]),
 <a list of 10 Patch objects>)

Save your results back to geojson


In [9]:
metrics.scoresToGeojson(myDistrict, 'polsbypopper', 'test/data/MN_Senate_2017_polsby.geojson')

In [10]:
metrics.scoresToGeojson(myDistrict, 'reock', 'test/data/MN_Senate_2017_reock.geojson')

In [ ]: