Skip to content

Instantly share code, notes, and snippets.

@hmurraydavis
Created November 9, 2014 13:40
Show Gist options
  • Save hmurraydavis/896a7239a42fec54c023 to your computer and use it in GitHub Desktop.
Save hmurraydavis/896a7239a42fec54c023 to your computer and use it in GitHub Desktop.
Python Bar Graph Base
import pylab as plt
plt.clf(); plt.close()
coNos = [1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0]
readingScores=[526,493,500,494,483,481,459,449,405]
mathScores = [562,496,487,492,466,483,468,421,387]
scienceScores=[542,501,502,514,470,488,478,447,415]
countries = ["Singapore",
"OECD\nAverage",
"United\nStates",
"United\nKingdom",
"Greece",
"Spain",
"Russia",
"Chile",
"Jordan"]
shift=0.2
plt.bar(coNos, readingScores, width=shift, color='r', align='center',label='Reading Scores')
coNos[:] = [x - shift for x in coNos]
plt.bar(coNos, scienceScores, width=shift, color='b', align='center',label='Science Scores')
plt.xticks(coNos, countries)
coNos[:] = [x - shift for x in coNos]
plt.bar(coNos, mathScores, width=shift, color='g', align='center',label='Math Scores')
plt.legend()
plt.xlabel("Countries",fontsize=14)
plt.ylabel("OECD Score",fontsize=14)
plt.title("OECD Scores by Country",fontsize=20)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment