File:Age structure aachen vs germany.svg

Summary

Description
English: The age structure of Aachen compared to that of Germany, in groups of ten years. (2014)

Source for Aachen: http://www.aachen.de/de/tourismus_stadtinfo/pdf/statistik/zahlendatenfakten.pdf

Source for Germany: http://de.statista.com/statistik/daten/studie/1351/umfrage/altersstruktur-der-bevoelkerung-deutschlands/

Created using Python, numpy and matplotlib.
Date
Source Own work
Author Xjcl
SVG development
InfoField
Source code
InfoField

Python code

Source code
import numpy as np
import matplotlib.pyplot as plt
from collections import namedtuple

A = namedtuple('A', 'a d')
A.__add__ = lambda self, other:  A(self.a + other.a, self.d + other.d)

t0009 =  716409+ 695923+ 694252+ 677136+ 689254+ 679327+ 697830+ 696484+ 684010+ 697726
t1019 =  722241+ 722852+ 735595+ 753292+ 786644+ 788875+ 808124+ 834306+ 825939+ 811944
t2029 =  828045+ 860603+ 903296+ 943635+1040072+1030503+1058649+1038497+1025737+1004003
t3039 = 1006078+1015013+1041919+1033777+1028891+ 980874+ 968335+ 959785+ 942439+ 917148
t4049 =  930754+ 939555+1020494+1126979+1172627+1261493+1322427+1358443+1397460+1401871
t5059 = 1428030+1415594+1369343+1349727+1304016+1267315+1194923+1166699+1132685+1095293
t6069 = 1072319+1034704+1030503+1004975+ 999121+ 962406+ 875830+ 819270+ 710420+ 622091
t70p  =  825875+ 832191+ 800307+ 961770+ 998866+ 967580+ 882551+ 803194+ 735405+ 701395\
      +  622741+ 476399+ 449159+ 428799+ 419672+2140804

s = sum([t0009, t1019, t2029, t3039, t4049, t5059, t6069, t70p])
p = [A( 7.6, t0009/s*100), A( 9.1, t1019/s*100), A(22.2, t2029/s*100), A(12.9, t3039/s*100),
     A(12.4, t4049/s*100), A(12.7, t5059/s*100), A( 9.4, t6069/s*100), A(13.7, t70p/s*100)]

xoff = .47
ind = np.arange(2) + xoff    # the x locations for the groups
width = .66       # the width of the bars

ax = plt.subplot(111)
ax.set_ylim([0,100])

# has to use '+' here because else wikipedia breaks, lol
cols = [[1,.7,.7], [1,.76,.64], [1,1,.4], [.76,1,.64], [.6,1,.8], [.6,.8,1]] + ['#D1BCF9', '#C69FE6']
labels = ['0-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60-69', '70+']


# plot the bars. iterate in reverse so the legend has '70+' on top, not '0-9'
for i, q in enumerate(p):
    j = len(p) - i - 1
    plt.bar(ind, p[j], width, color=cols[j], bottom=sum(p[:j], A(0,0)), label=labels[j])

for i, q in enumerate(p):  # 'X%' labels
    for k in [0,1]:
        plt.text(xoff+k+width/2, sum(p[:i], A(0,0))[k] + q[k]/2, str(round(q[k]))+'%', ha='center', va='center')


plt.xticks(ind + width/2, ('Aachen', 'Germany'))
plt.yticks(np.arange(0, 101, 10))

major_ticks = np.arange(0, 101, 10)
ax.set_yticks(major_ticks)
ax.yaxis.grid(which='major', alpha=.8)

ax.set_axisbelow(True)

for tick in ax.xaxis.get_major_ticks():
    tick.label.set_fontsize(16)
for tick in ax.yaxis.get_major_ticks():
    tick.label.set_fontsize(16)


# Shrink current axis by 20%
box = ax.get_position()
ax.set_position([box.x0, box.y0, box.width * 0.7, box.height])
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')

# Put a legend to the right of the current axis
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5))

plt.gcf().set_size_inches(5, 8)

plt.savefig('age_structure_aachen_vs_germany.svg')

Licensing

I, the copyright holder of this work, hereby publish it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
Category:CC-BY-SA-4.0#Age%20structure%20aachen%20vs%20germany.svgCategory:Self-published work
Category:SVG created with Matplotlib Category:Demographics
Category:CC-BY-SA-4.0 Category:Demographics Category:SVG created with Matplotlib Category:Self-published work Category:Valid SVG created with Matplotlib code