import pygal
from pygal.style import Style
##2017 rahvastiku püramiid
custom_style = Style(
colors=('#3435FF', '#FC312D', '#DEE4F4', '#F5D9DB', '#94B0D4', '#FA9696'))
ages = [(34667, 37909, 32723, 29175, 32695, 43150, 41135, 37685, 36518, 34935, 31780, 30508, 26762, 23077, 16242, 13830, 8271, 5607),
(32781, 32781, 31023, 27360, 31023, 41106, 40938, 38147, 38113, 38508, 36674, 38650, 37242, 35774, 28083, 29723, 21361, 20024),
(820, 1053, 995, 987, 903, 1766, 1954, 1876, 2601, 2670, 3486, 4790, 4822, 4055, 1861, 2936, 1487, 1112 ),
(829, 1024, 987, 865, 891, 1583, 1779, 1730, 2165, 2084, 2830, 4222, 5072, 5010, 2856, 5629, 3533, 3411),
(14, 28, 55, 180, 540, 3084, 3795, 4735, 4947, 4371, 4351, 4745, 4228, 2951, 1210, 1215, 551, 291),
(14, 22, 47, 169, 406, 1679, 2078, 2994, 3518, 3098, 3521, 4308, 4062, 3629, 1672, 2416, 1537, 1465),
(486, 414, 359, 373, 1861, 2484, 2284, 1949, 1770, 1545, 1386, 1150, 867, 693, 444, 334, 121, 55),
(409, 409, 337, 407, 2014, 1615, 1177, 832, 697, 577, 562, 572, 439, 492, 301, 348, 172, 151),
]
types = ['Eesti kodanikud ♂', 'Eesti kodanikud ♀',
'Venemaa kodanikud ♂', 'Venemaa kodanikud ♀',
'Määratlemata kodakondsusega ♂','Määratlemata kodakondsusega ♀',
'Muude riikide kodanikud ♂', 'Muude riikide kodanikud ♀']
pyramid_chart = pygal.Pyramid(human_readable=True, legend_at_bottom=True, style=custom_style)
pyramid_chart.title = 'Eesti rahvastikupüramiid kodakondsuse kaupa 01.01.2017'
pyramid_chart.x_labels = '0-4', '5-9', '10-14', '15-19', '20-24', '25-29', '30-34', '35-39', '40-44', '45-49', '50-54', '55-59', '60-64', '65-69', '70-74', '75-79', '80-84', '85 ja vanemad'
## map(lambda x: str(x) if not x % 5 else '', range(90))
for type, age in zip(types, ages):
pyramid_chart.add(type, age)
pyramid_chart.render_to_file('bar_chart.svg')
pyramid_chart.render_to_png('bar_chart.png')