Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import matplotlib
  2. import matplotlib.pyplot as plt
  3. import pandas as pd
  4. df = pd.read_csv('population.csv',skiprows=3)
  5. df.set_index('Country Code',inplace=True)
  6. excep = ['EAP','SAS','TEA','TEC','TLA','TMN','TSA','TSS',
  7. 'IBT','IDA','IDB','OED','HIC','LTE','PRE','PST',
  8. 'IDX','SSA','LDC','ECS','HPC','LIC','LCN','LAC',
  9. 'EUU','FCS','LMY','MIC','IBD','EAR','LMC','UMC',
  10. 'EAS','SSF','MEA','ECA','ARB','MNA','NAC','EMU',
  11. 'CEB']
  12. df.drop(excep,inplace=True)
  13. plt.rcParams['font.sans-serif']=['SimHei']
  14. plt.ion()
  15. for y in range(1960,2018):
  16. plt.clf()
  17. plt.gca().invert_yaxis()
  18. plt.title(str(y))
  19. ndf = df.sort_values(by=str(y),ascending=False)
  20. ndf = ndf[1:10]
  21. Pic = plt.barh(ndf["Country Name"],ndf[str(y)])
  22. for rect in Pic:
  23. w=rect.get_width()
  24. plt.text(w,rect.get_y()+rect.get_height()/2,'%d'%int(w),ha='left',va='center')
  25. plt.pause(0.05)
  26. while True:
  27. plt.pause(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement