Skip to content

Instantly share code, notes, and snippets.

@niftycode
Last active April 24, 2017 16:54
Show Gist options
  • Save niftycode/5e6817c9d1afe269b7ae7c07eb1db9c4 to your computer and use it in GitHub Desktop.
Save niftycode/5e6817c9d1afe269b7ae7c07eb1db9c4 to your computer and use it in GitHub Desktop.
Election presidentielle 2017 - a bar chart created with Python and matplotlib
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('seaborn-bright')
fig, ax = plt.subplots()
candidats = ('Marine Le Pen', 'Emmanuel Macron', 'François Fillon', 'Benoît Hamon', 'Jean-Luc Mélenchon')
voter = [21.7,23.9,20,6.3,19.2]
y_pos = np.arange(len(candidats))
couleur = ['#000000', '#dbb243', '#2e42d3', '#e54fe3', '#f23434']
plt.title('Election presidentielle 2017')
plt.ylabel('Vote en %')
plt.xlabel("Candidats")
plt.ylim(0, 30)
c_rects = plt.bar(y_pos, voter, align='center', alpha=0.6, color=couleur)
ax.set_xticks(range(len(candidats)))
ax.set_xticklabels(candidats, rotation='vertical')
def autolabel(rects):
for rect in rects:
height = rect.get_height()
ax.text(rect.get_x() + rect.get_width()/2., height + 1,
'%.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