-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworld_by_country.py
51 lines (39 loc) · 2.03 KB
/
world_by_country.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.offsetbox import OffsetImage,AnnotationBbox
import datetime
import cairosvg
flagDir = "/home/strawberry/Documents/travel/country-flag-icons/images/svg/"
name_convert = {"Spain":"esp", "Germany":"deu", "China":"chn",'USA':'usa','Italy':'ita','United Kingdom':'gbr',
'Austria':'aus','Slovakia':'svk','Singapore':'sgp','Indonesia':'idn','Vietnam':'vnm','Thailand':'tha',
'Malaysia':'mys','Netherlands':'nld','Russia':'rus','Sweden':'swe',"Denmark":'dnk','Czechia':'cze',
'EU':'eu','Belarus':'blr','Canada':'can','Korea':'kor','Brazil':'bra','Taiwan':'twn','Iran':'irn','Hong Kong':'hkg',
'Japan':'jpn','Ukraine':'ukr','Switzerland':'che'}
def get_flag(name):
path = flagDir+name_convert[name]+".svg"
png_path = flagDir+name_convert[name]+".png"
cairosvg.svg2png(url=path, write_to=png_path)
im = plt.imread(png_path)
return im
def offset_image(coord, name, ax):
img = get_flag(name)
factor = 1/(img.shape[0]/30.0)
im = OffsetImage(img, zoom=factor)
im.image.axes = ax
ab = AnnotationBbox(im, (coord, 0), xybox=(0., -20.), frameon=False,
xycoords='data', boxcoords="offset points", pad=0)
ax.add_artist(ab)
countries = ["China", "Russia", "EU", "USA",'Belarus','Canada','Korea','United Kingdom']#,'Brazil','Taiwan','Singapore','Iran','Hong Kong','Japan','Ukraine','Switzerland','Vietnam']
valuesA = [9, 8, 7,7,2,2,2,2]#,1,1,1,1,1,1,1,1,1]
fig, ax = plt.subplots()
ax.bar(range(len(countries)), valuesA, width=0.5,align="center")
ax.set_xticks(range(len(countries)))
ax.set_xticklabels(countries,fontsize=16)
ax.tick_params(axis='x', which='major', pad=36)
for i, c in enumerate(countries):
offset_image(i, c, ax)
plt.xlabel('Countries', fontsize=18)
plt.ylabel('Number of universities in top50', fontsize=18)
plt.title('Countries by number of top universities at ACM ICPC', fontsize=24)
plt.show()
fig.savefig('worlds.png', format='png',bbox_inches='tight',dpi=600)