Exemplo n.º 1
0
def test_worldmap_i18n_clear():
    set_countries(_COUNTRIES, True)
    wmap = World()
    wmap.add('countries', dict(fr=12))
    set_countries({'fr': 'Frankreich'}, clear=True)
    q = wmap.render_pyquery()
    assert len(
        q('.country.color-0')
    ) == 1
    assert 'Frankreich' in q('.country.fr').text()
Exemplo n.º 2
0
def test_worldmap():
    set_countries(_COUNTRIES, True)
    datas = {}
    for i, ctry in enumerate(COUNTRIES):
        datas[ctry] = i

    wmap = World()
    wmap.add('countries', datas)
    q = wmap.render_pyquery()
    assert len(
        q('.country.color-0')
    ) == len(COUNTRIES)
    assert 'France' in q('.country.fr').text()
Exemplo n.º 3
0
from pygal_maps_world.maps import World
from pygal.style import Style

style = Style(font_family='googlefont:Raleway')

blue = Style(colors=('blue', ))
worldmap_chart = World(style=blue)
worldmap_chart.title = 'Country of residence'
worldmap_chart.add(
    'Students', {
        'by': 1,
        'ca': 1,
        'ch': 1,
        'cn': 1,
        'de': 4,
        'eg': 1,
        'in': 11,
        'kr': 1,
        'ru': 1,
        'sg': 1,
        'us': 4,
        'gr': 1
    })
worldmap_chart.render_to_png("./world.png")
Exemplo n.º 4
0
import json
import pygal
from pygal_maps_world.maps import World
wm = World()
wm.title = 'Populations of Countries in North America'
wm.add('North America', {'ca': 3412600, 'us': 30934000, 'mx': 113423000})
wm.render_to_file('na_populations.svg')

Exemplo n.º 5
0
#-------------------------------------------------------------------------------
# Name:        module1
# Purpose:
#
# Author:      HO0me
#
# Created:     21/04/2019
# Copyright:   (c) HO0me 2019
# Licence:     <your licence>
#-------------------------------------------------------------------------------

from pygal_maps_world.maps import World

wm = World()
wm.title = 'Populations of countries in North America'

wm.add('North America', {'ca': 34126000, 'mx': 113423000, 'us': 309349000})
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('na_americas.svg')
Exemplo n.º 6
0
        country_name = gdp_dict["Country Name"]
        gdp = int(float(
            gdp_dict["Value"]))  # Armazenadas em um formato numérico.
        code_country = get_country_code(country_name)
        if code_country:
            cc_gdps[code_country] = gdp
            ''' O dicionário armazena o código do país como chave e a população
                como valor sempre que o código é devolvido. '''
# Agrupa os países em três níveis populacionais.
cc_gdps_1, cc_gdps_2, cc_gdps_3 = {}, {}, {}
for cc, gdp in cc_gdps.items():
    if gdp < 5000000000:
        cc_gdps_1[cc] = round(gdp / 1000000000)
    elif gdp < 50000000000:
        cc_gdps_2[cc] = round(gdp / 1000000000)
    else:
        cc_gdps_3[cc] = round(gdp / 1000000000)

# Vê quantos píses estão em cada nível.
print(len(cc_gdps_1), len(cc_gdps_2), len(cc_gdps_3))
wm_style = RotateStyle('#336699')
wm = World(style=wm_style)  # Criamos uma instância da classe World().
wm.title = 'Global GDP in 2016, by Country (in billions USD)'  # Definimos o atributo title() do mapa.
# usamos o método add() que aceita um rótulo (primiro argumento) e um dicionário de códigos de países (segundo argumento).
wm.add('0-5bn', cc_gdps_1)
wm.add('5bn-50bn', cc_gdps_2)
wm.add('>50bn', cc_gdps_3)

# O método render_to_file() cria um arquivo svg contendo o mapa, que poderá ser aberto no navegador.
wm.render_to_file('Global_gdp.svg')
Exemplo n.º 7
0
 def __init__(self, title):
     '''
     Constructor
     '''
     self.wmap = World()
     self.wmap.title = title
Exemplo n.º 8
0
def world_population():
    filename = "population_data.json"
    with open(filename) as f:
        pop_data = json.load(f)

    cc_pop = {}
    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_pop[code] = population

    #grouping countries into 3 pop levels
    cc_pops1, cc_pops2, cc_pops3 = {}, {}, {}
    for cc, pop in cc_pop.items():
        if pop < 10000000:
            cc_pops1[cc] = pop
        elif pop < 1000000000:
            cc_pops2[cc] = pop
        else:
            cc_pops3[cc] = pop

    print(len(cc_pops1), len(cc_pops2), len(cc_pops3))

    #building a world map
    wm_style = RotateStyle("#336699", base_style=LightColorizedStyle)
    wm = World(style=wm_style)
    wm.title = "World Population in 2010, by Country"
    wm.add('0-10m', cc_pops1)
    wm.add('10m-1bn', cc_pops2)
    wm.add('>1bn', cc_pops3)

    wm.render_to_file('world_population.svg')
Exemplo n.º 9
0
cc_pibs = {}
for pop_dict in pop_data:
    if pop_dict['Year'] == 2016:
        country_name = pop_dict['Country Name']
        country_pib = int(float(pop_dict['Value']))
        code = get_country_code(country_name)
        if code:
            cc_pibs[code] = country_pib

# Agrupando os países pelo seu PIB.
cc_pibs_1, cc_pibs_2, cc_pibs_3 = {}, {}, {}
for cc, pib in cc_pibs.items():
    if pib < 50_000_000_000:
        cc_pibs_1[cc] = pib
    elif pib < 51_000_000_000:
        cc_pibs_2[cc]: pib
    else:
        cc_pibs_3[cc] = pib

# Vizualiza quantos países estão em cada nível.
print(len(cc_pibs_1), len(cc_pibs_2), len(cc_pibs_3))


w_style = RS('#902020', base_style=LCS)
w = World(style=w_style)
w.title = 'PIB Population in 2016, by Country'
w.add('0-50bn', cc_pibs_1)
w.add('>50bn', cc_pibs_3)

w.render_to_file("Estudos/PYTHON/Python-VisualizacaoDeDados/Dados-Gráficos/Dowload_de_dados/PIB_Population.svg")
Exemplo n.º 10
0
import pandas as pd
import sqlite3
import sqlalchemy
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from pygal_maps_world.maps import World

# df = pd.read_csv('tes.csv')
# listnama = list(df['nama'])
# # df = df.nama.replace(listnama,['Alpha','Bravo','Charlie','Delta','Echo'])
# listnama.remove('Andi')
# print(listnama)
# print(df.unique())
worldmap_chart = World()
worldmap_chart.title = 'Some countries'
worldmap_chart.add(
    '', {
        'af': 14,
        'bd': 1,
        'by': 3,
        'cn': 1000,
        'gm': 9,
        'in': 1,
        'ir': 314,
        'iq': 129,
        'jp': 7,
        'kp': 6,
        'pk': 1,
        'ps': 6,
        'sa': 79,
Exemplo n.º 11
0
with open(filename) as file:
    pop_data = json.load(file)

population_dict = {}

for pop_dict in pop_data:
    if pop_dict['Year'] == 2016:
        country_name = pop_dict['Country Name']
        population = pop_dict['Value']
        code = get_country_code(country_name)
        if code:
            population_dict[code] = population

sorted_pop = dict(sorted(population_dict.items(), key=operator.itemgetter(1)))
res = []

for item in chunks(sorted_pop, len(sorted_pop) // 10):
    res.append(item)

map_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm = World(wm_style=map_style)
wm.title = 'World Population in 2016'
temp = 0
for group in res[:-1]:
    mean = millify(int(sum(group.values()) / len(group)))
    title = '%s - %s' % (temp, mean)
    wm.add(str(title), group)
    temp = mean
wm.add('> %s' % temp, res[-1])
wm.render_to_file('resources/world_population 2016.svg')
Exemplo n.º 12
0
"""Americas"""

import os
from pygal_maps_world.maps import World

WM = World()
WM.title = 'North, Central and South America'

WM.add('North America', ['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'
])

SAVE_PATH = os.path.realpath(os.path.dirname(__file__)) + "\\svg"
WM.render_to_file(os.path.join(SAVE_PATH, 'americas.svg'))
Exemplo n.º 13
0
from pygal_maps_world.maps import World

wm = World()
wm.force_uri_protocol = 'http'

wm.title = "Map of Central America"
wm.add('North America', {'ca': 84949494949, 'mx': 494794164, 'us': 99794616})

wm.render_to_file('map.svg')
Exemplo n.º 14
0
filename = 'gdp_json.json'
with open(filename) as f:
    gdp_data = json.load(f)

gdps = {}
for gdp_dict in gdp_data:
    if gdp_dict['Year'] == 2016:
        country_name = gdp_dict['Country Name']
        value = int(float(gdp_dict['Value']))
        code = get_country_code(country_name)
        if code:
            gdps[code] = value

gdp_1, gdp_2, gdp_3 = {}, {}, {}
for name, gdp in gdps.items():
    if gdp < 50000000000:
        gdp_1[name] = gdp
    elif gdp < 100000000000:
        gdp_2[name] = gdp
    else:
        gdp_3[name] = gdp

wm_style = RotateStyle('#338899', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = 'World Gdp in 2016, by Country'
wm.add('<50000000000', gdp_1)
wm.add('<100000000000', gdp_2)
wm.add('>100bn', gdp_3)
wm.render_to_file('gdp_2016.svg')
Exemplo n.º 15
0
    pop_data = json.load(f)

cc_populations = {}
for pop_dict in pop_data:
    if pop_dict['Year'] == "1960":
        country_name = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        # print(country_name + ": "+ str(population))
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population
# print(cc_populations)
cc_pop_10yi, cc_pop_wan, cc_pop_less = {}, {}, {}
for cc, pop in cc_populations.items():
    if pop > 100000000:
        cc_pop_10yi[cc] = pop
    elif pop < 10000000:
        cc_pop_wan[cc] = pop
    else:
        cc_pop_less[cc] = pop

wm_style = LightColorizedStyle  #RotateStyle('#336699')
wm = World(style=wm_style)
wm.title = 'World Population in 2010,by Country'

wm.add('1亿', cc_pop_10yi)
wm.add('千万', cc_pop_wan)
wm.add('少于一千万', cc_pop_less)

wm.render_to_file('world_population.svg')
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')
Exemplo n.º 17
0
from pygal.style import RotateStyle

filename = 'population_data.json'

with open(filename) as f:
    gdp_data = json.load(f)


def get_country_code(country):
    for code, name in COUNTRIES.items():
        if name == country:
            return code
    return None


gdp_all = {}
for gdp_dict in gdp_data:
    if gdp_dict['Year'] == '2010':
        country_name = gdp_dict['Country Name']
        value = int(float(gdp_dict['Value']))
        code = get_country_code(country_name)
        if code:
            gdp_all[code] = value

wm_style = RotateStyle('#336699')
wm = World(style=wm_style)
wm.title = 'World GDP in 2010'
wm.add('2010', gdp_all)

wm.render_to_file('gdp_world.svg')
            cc_population[country_code] = population
        else:
            print('ERROR - ' + country_name)

cc_pop1, cc_pop2, cc_pop3 = {}, {}, {}

for cc, pop in cc_population.items():
    if pop < 10000000:
        cc_pop1[cc] = pop
    elif pop < 1000000000:
        cc_pop2[cc] = pop
    else:
        cc_pop3[cc] = pop
print(len(cc_pop1), len(cc_pop2), len(cc_pop3))

# Set graph format and preferences
wm_style = pygal.style.RotateStyle('#336699', base_style=pygal.style.LightColorizedStyle)
world = World(style=wm_style)
wm = pygal.maps.world.World(style=wm_style)

# To set contents shown on the graph.
wm.title = "World Population in 2010,by Country"
wm.add('0-10m', cc_pop1)
wm.add('10-1bn', cc_pop2)
wm.add('>1bn', cc_pop3)
wm.render_to_file('world_population.svg')
		
	    
		
	
Exemplo n.º 19
0
import json
from country_code import get_country_code
from pygal_maps_world.maps import World

filename = 'data_version/population_data.json'
with open(filename) as f:
    data = json.load(f)
    # print(isinstance(data, list))

cc_population = {}
for item in data:
    if item['Year'] == '2010':
        country_name = item['Country Name']
        population = int(float(item['Value']))
        code = get_country_code(country_name)
        if code:
            cc_population[code] = population

wm = World()
wm.title = 'World Population in 2010, by Country'
wm.add('2010', cc_population)

wm.render_to_file('world_population.svg')
Exemplo n.º 20
0
file_name = 'population_data.json'
with open(file_name) as f:
    pop_data = json.load(f)

populations = {}
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:
            populations[code] = population

populations_group1, populations_group2, populations_group3 = {}, {}, {}
for code, population in populations.items():
    if population < 10000000:
        populations_group1[code] = population
    elif population < 1000000000:
        populations_group2[code] = population
    else:
        populations_group3[code] = population
print(len(populations_group1), len(populations_group2),
      len(populations_group3))

world_map_style = RS('#336699', base_style=LCS)
world_map = World(style=world_map_style)
world_map.title = 'World Population in 2010, by Country'
world_map.add('2010,1-1千万', populations_group1)
world_map.add('2010,1千万-10亿', populations_group2)
world_map.add('2010,>10亿', populations_group3)
world_map.render_to_file('fill_world_map3.svg')
Exemplo n.º 21
0
cc_populations = {}
# print the population of every country in 2010
for pop_dict in pop_data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
        code = get_country_code(country_name)
        population = int(float(pop_dict['Value']))
        if code:
            print(code + ': ' +
                  "{:,}".format(population))  # output as this format
            cc_populations[code] = population

cc_pop_1, cc_pop_2, cc_pop_3 = {}, {}, {}
for cc, pop in cc_populations.items():
    if pop < 10000000:
        cc_pop_1[cc] = pop
    elif pop < 100000000:
        cc_pop_2[cc] = pop
    else:
        cc_pop_3[cc] = pop

print(len(cc_pop_1), len(cc_pop_2), len(cc_pop_3))

wm = World()
wm.title = "World Population in 2010, by Country"
wm.add('0-10m', cc_pop_1)
wm.add('10m-100m', cc_pop_2)
wm.add('>100m', cc_pop_3)
wm.render_to_file('world_population.svg')
Exemplo n.º 22
0
class PWorldMap(object):
    '''
    classdocs
    '''
    def __init__(self, title):
        '''
        Constructor
        '''
        self.wmap = World()
        self.wmap.title = title

    def sample(self):
        self.wmap.add('F countries', ['fr', 'fi'])
        self.wmap.add('M countries', [
            'ma', 'mc', 'md', 'me', 'mg', 'mk', 'ml', 'mm', 'mn', 'mo', 'mr',
            'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz'
        ])
        self.wmap.add('U countries', ['ua', 'ug', 'us', 'uy', 'uz'])
        self.wmap.add('North America', {
            'ca': 84949494949,
            'mx': 494794164,
            'us': 99794616
        })

    def render(self, filename=None):
        '''
        render the map
        see http://www.pygal.org/en/stable/documentation/output.html
        '''
        if filename is None:
            self.wmap.render_in_browser()
        else:
            if filename.endswith(".png"):
                self.wmap.render_to_png(filename)
            else:
                self.wmap.render_to_file(filename)
import json
from pygal_maps_world.maps import World
from country_codes import get_country_code

file_name = 'population_data.json'
with open(file_name) as f:
    pop_data = json.load(f)

populations = {}
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:
            populations[code] = population

world_map = World()
world_map.title = 'World Population in 2010, by Country'
world_map.add('2010', populations)
world_map.render_to_file('fill_world_map.svg')
Exemplo n.º 24
0
# americas
# Created by JKChang
# 22/01/2018, 21:08
# Tag:
# Description: 

from pygal_maps_world.maps import World

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

wm.add('North America', ['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('resources/americas.svg')
Exemplo n.º 25
0
from pygal_maps_world.maps import World

wm = World()
wm.title = "Population of North American Countries"
wm.add('North America', {'ca': 34126000, 'us': 30930000, 'mx': 113425670})

wm.render_to_file("Population map.svg")
Exemplo n.º 26
0
    'bo', 'ar','ir', 'np', 'cu', 'dk', 're', 'mt', 'mk', 'kr', 'al', 'ke', 'md',
    'pk', 'na', 'uy', 'om', 'la', 'gf', 'hn', 'ml', 'ph', 'mk', 'sv', 'cr',
    'gu', 'mc', 'ht', 'gt', 'ee', 'ec','tj','me', 'ba', 'kg', 'cy', 'id', 'jo', 
    'dj','cv', 'sc', 'lt', 'sm', 'sz', 'kz',
    'sy', 'mo', 'tl', 'pr', 'bw', 'mn', 'do', 'ge', 'gl', 'lv', 'kp',
    'am', 'lb', 'mw', 'ao', 'ye', 'ug','pa', 'lk', 'az', 'so', 'sg', 'li',
    'gh', 'ng','ga', 'sa','by','uz', 'gm', 
    'aq', 'bh', 'tz', 'ci', 'sl', 'sr', 'tm', 'kh', 'mm', 'jm',
    'gn', 'bj', 'mv', 'rw', 'st'
]
dfmap = df.country.replace(countrylist, pygalList)
dfmap = dfmap[dfmap.isin(pygalList)]
mappingDict = dict(dfmap.value_counts())
#============================================================================
#World map charting
wmChart = World()
wmChart.title = 'Number of Climbing Routes in Each Country According to 8a.nu Log Book'
wmChart.add('Number of Routes',mappingDict)
wmChart.render_to_file('routemap.svg')
#=================================================================================
#Number of grades in each country
#Split country into 3 groups with >100k route , with>2.5k route & country with less route
country1 = country.loc[country>25000]
country1 = list(country1.index)
country2 = country.loc[country.between(5000,25000)]
country2 = list(country2.index)
country3 = country.loc[country<5000]
country3 = list(country3.index)
filtered1 = df[df['country'].isin(country1)]
#==========================================================================
#Heatmap of route grades & country
Exemplo n.º 27
0
# Utworzenie słownika danych dotyczących populacji
cc_populations = {}
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

# Podzieleniw państw na trzy grupy według liczebności populacji
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
# Przygotowanie wykresu

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

wm.force_url_protocol = 'http'
wm.title = 'Populacja na świecie w 2010 roku. (dane dla poszczególnych państw)'
wm.add('0 - 10 mln', cc_pops_1)
wm.add('10 mln - 1 mld', cc_pops_2)
wm.add('> 1 mld', cc_pops_3)

wm.render_to_file('world_population.svg')
Exemplo n.º 28
0
import pygal

from pygal_maps_world.maps import World

w = World()
w.title = 'Populations of Countries in North America'
w.add('North America', {'ca': 34126000, 'us': 30934900, 'mx': 113423000})

w.render_to_file('Estudos/PYTHON/Python-VisualizacaoDeDados/Dados-Gráficos/Dowload_de_dados/na_populations.svg')
Exemplo n.º 29
0
def get_country_code(country):
    for code, name in COUNTRIES.items():
        if name == country:
            return code
    return None


filename = 'high_tech_exports.csv'

with open(filename) as f:
    reader = csv.reader(f)

    exports_by_country = {}
    for row in reader:
        if row[-4]:
            if row[-4] != '2016':
                exports_by_country[row[0]] = int(float(row[-4]))

data_to_plot = {}
for k, v in exports_by_country.items():
    code = get_country_code(k)
    data_to_plot[code] = v

wm_style = RotateStyle('#336699')
wm = World(style=wm_style)
wm.title = 'High Technology Exports in the world in 2015'
wm.add('2015', data_to_plot)

wm.render_to_file('high_tech_exports.svg')
Exemplo n.º 30
0
cc_populations = {}
for pop_dict in pop_data:
    # print(pop_dict['Year']==2016)
    if pop_dict['Year'] == 2016:
        # print(pop_dict['Country Name'])
        country_name = pop_dict['Country Name']

        # 有些值是小数,先转为float再转为int
        population = int(float(pop_dict['Value']))
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population  #{'中国': '13亿'}

# 为了使颜色分层更加明显
cc_populations_1, cc_populations_2, cc_populations_3 = {}, {}, {}
for cc, population in cc_populations.items():
    if population < 10000000:
        cc_populations_1[cc] = population
    elif population < 1000000000:
        cc_populations_2[cc] = population
    else:
        cc_populations_3[cc] = population

wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
world = World(style=wm_style)
world.title = 'World Populations in 2015, By Country'
world.add('0-10m', cc_populations_1)
world.add('10m-1bn', cc_populations_2)
world.add('>1bn', cc_populations_3)
world.render_to_file('world_population_2015.svg')
Exemplo n.º 31
0
#Print the 2010 population for each country
world_maps = {}
highest3 = {}
pop_list =[]
for pop_dict in data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        code = return_code(country_name)
        pop_list.append(population)
        #print(country_name+': ' + population+ '>>>'+ return_code(country_name))
        if code:
            world_maps[code] = population
        else:
            print('Error '+ country_name)
cc_pops1 = {}
cc_pops2 = {}
for cc, pop in world_maps.items():
    if pop <10000000:
        cc_pops1[cc] = pop
    else:
        cc_pops2[cc] = pop
wm = World()
wm_style = RotateStyle('#723ac3')
wm = World(style=wm_style)
wm.title = "World Population in 2010"
wm.add('World population', world_maps)
wm.add('Top 5 Most Populated', cc_pops1)
wm.add('toppp',cc_pops2)
wm.render_to_file('world_map.svg')
Exemplo n.º 32
0
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')
Exemplo n.º 33
0
from pygal_maps_world.maps import World

wm = World()
wm.title = 'North,Central,and South Amercia'
wm.add('North America', {'ca':34126000,'mx':309349000,'us':113423000})
wm.add('Central America',['bz','cr','gt','hn','ni','pa','sv'])
wm.add('South Ameirca',['ar','bo','br','cl','co','ec','gf','gy','pe','py','sr','uy','ve'])
wm.render_to_file('americas.svg')
        else:
            print('ERROR - ' + country_name)

# Group the countries into 3 population levels.
cc_pops_1 = {}
cc_pops_2 = {}
cc_pops_3 = {}

for cc, pop in cc_populations.items():
    if pop < 100000000:
        cc_pops_1[cc] = pop
    elif pop < 1000000000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop

# See how many countries are in each level.
print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3))

# wm = World()
wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm = World(style=wm_style)

wm.title = 'World Population in 2010, by Country'
# wm.add('2010', cc_populations)
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')
from pygal_maps_world.maps import World

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

wm.add('North America', ['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')