Created
September 25, 2017 09:31
-
-
Save niftycode/f85f8e4b2dd31ac1ed37a963e2ec458f to your computer and use it in GitHub Desktop.
German Federal Election 2017 (Bundestagswahl)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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