In [1]:
import json
import matplotlib.dates as mdates
import matplotlib.pyplot as plt
from pylab import rcParams
rcParams['figure.figsize'] = 20, 10
%matplotlib inline

In [2]:
with open('./alive_data.json') as f:
    data = json.load(f)

In [36]:
brittany['2013']


Out[36]:
{'alive': 4222,
 'alive_chance': 0.993831477092654,
 'born': 4248,
 'born_unadjusted': 3918}

In [32]:
brittany = data['data']['Violet']['F']
years = tuple(sorted(brittany.keys()))
alive_counts = [brittany[year]['alive'] for year in years]
born_counts = [brittany[year]['born'] for year in years]

total_alive = sum(alive_counts)
mid_point = total_alive // 2 # floor

seen = 0
idx = 0
while idx < len(alive_counts):
    seen += alive_counts[idx]
    if seen >= mid_point:
        break
    idx += 1

print('{} years old ({})'.format(data['alive_year'] - int(years[idx]), years[idx]))

years = [int(y) for y in years]
counts = born_counts

fig, ax = plt.subplots(1)
ax.bar(years, alive_counts, 1, color='gray')
ax.plot(years, born_counts, color='red')
ax.bar(int(years[idx]), alive_counts[idx], 1, color='purple')

fig.autofmt_xdate()
ax.fmt_xdata = mdates.DateFormatter('%Y')
plt.show()


10 years old (2006)