for pop_dict in pop_data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population

# 根据人口数量将所有的国家分成三组
cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for cc, pop in cc_populations.items():
    if pop < 10000000:
        cc_pops_1[cc] = pop
    elif pop < 1000000000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop

# 看看每组分别包含多少个国家
print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3))

wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)

wm._title = 'World Population in 2010, by Country'
wm.add('0-10m', cc_pops_1)
wm.add('10m-1bn', cc_pops_2)
wm.add('>1bn', cc_pops_3)

wm.render_to_file('world_population.svg')
Exemple #2
0
"""
@author: MrYang 
@contact: [email protected]
@site: www.example.com
@file: americas.py
@time: 18/12/2017 10:35 PM
"""
from pygal_maps_world.maps import World

wm = World()
wm._title = 'North, Central, and South America'

wm.add('North Amerca', ['ca', 'mx', 'us'])
wm.add('Central America', ['bz', 'cr', 'gt', 'hn', 'ni', 'pa', 'sv'])
wm.add('South America', ['ar', 'bo', 'br', 'cl', 'co', 'ec',
                         'gf', 'gy', 'pe', 'py', 'sr', 'uy', 've'])

wm.render_to_file('americas.svg')
from pygal_maps_world.maps import World

world_map = World()
world_map._title = 'North, Central, and South America'

world_map.add('North America', ['ca', 'mx', 'us'])
world_map.add('Central America', ['bz', 'cr', 'gt', 'hn', 'ni', 'pa', 'sv'])
world_map.add('South America', ['ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf',
                                'gy', 'pe', 'py', 'sr', 'uy', 've'])

world_map.render_to_file('americas.svg')

"""
@author: MrYang 
@contact: [email protected]
@site: www.example.com
@file: na_populations.py
@time: 18/12/2017 10:41 PM
"""
from pygal_maps_world.maps import World

wm = World()

wm._title = 'Populations of Countries in North America'
wm.add('North America', {'ca':34126000, 'us':309349000, 'mx':113423000})

wm.render_to_file('na_populations.svg')