Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
German Federal Election 2017 (Bundestagswahl)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Election, German Bundestag 2017
Version: 1.0
Python 3.6
Date created: 25/09/2017
"""
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('seaborn-bright')
fig, ax = plt.subplots()
parties = ('CDU', 'SPD', 'FDP', 'Grüne', 'AfD', 'Linke')
voter = [33.0, 20.5, 10.7, 9.2, 12.6, 9.2]
y_pos = np.arange(len(parties))
color = ['#000000', '#c51d1e', '#f6c909', '#0c9941', '#2b7ab4', '#bb4894']
plt.title('Bundestagswahl 2017')
plt.ylabel('Stimmen in %')
plt.xlabel('Parteien')
plt.ylim(0, 40)
c_rects = plt.bar(y_pos, voter, align='center', alpha=0.6, color=color)
ax.set_xticks(range(len(parties)))
ax.set_xticklabels(parties, rotation='vertical')
def autolabel(rects):
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., height + 1.5,
'%.1f' % float(height),
ha='center', va='bottom')
autolabel(c_rects)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.