population = pop_dict['Value']
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population
        else:
            # print('error-', country_name)
            pass
    else:
        pass

# 根据人口数量将所有国家分为3组
cc_pops1, cc_pops2, cc_pops3 = {}, {}, {}
for cc, pop in cc_populations.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))

wm_style = RotateStyle('#336699')
wm = World(style=wm_style)
wm.title = 'world population in 2010, by country'
# wm.add('2010', cc_populations)
wm.add('0-10m', cc_pops1)
wm.add('10m-1bn', cc_pops2)
wm.add('>1bn', cc_pops3)

wm.render_to_file('world_population.svg')
Ejemplo n.º 2
0
from pygal.maps.world import World

wm = World()
wm.title = 'North, Central and South America'
wm.add('North America', {'ca': 34126000, 'mx': 113423000, 'us': 309349000})

wm.render_to_file('images/americas.svg')
Ejemplo n.º 3
0
import pygal
from pygal.maps.world import World

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

wm.add('North America', {'ca': 34126000, 'mx': 309349000, 'us': 113423000})

wm.render_to_file('na_populaton.svg')
Ejemplo n.º 4
0
# 19.09.2017
from pygal.maps.world 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')
Ejemplo n.º 5
0
	if gdp_dict["Year"] == 2010:
		country_name = gdp_dict["Country Name"]
		gdp = int(gdp_dict["Value"])
		code = get_country_code(country_name)
		if code:
			cc_gdps[code] = gdp 

# Group the countries into 3 gdp levels.
#  Less than 5 billion, less than 50 billion, >= 50 billion.
#  Also, convert to billions for displaying values.
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)

# See how many countries are in each level.        
print(len(cc_gdps_1), len(cc_gdps_2), len(cc_gdps_3))

wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.title = 'Global GDP in 2014, by Country (in billions USD)'
wm.add('0-5bn', cc_gdps_1)
wm.add('5bn-50bn', cc_gdps_2)
wm.add('>50bn', cc_gdps_3)
    
wm.render_to_file('global_gdp.svg')
Ejemplo n.º 6
0
from countries import get_country_code
filename = 'population_data.json'
with open(filename) as f:
    pop_data = json.load(f)
#print 2010 population of each country
cc_population = {}  #a dictionary to hold country_code - population
for data_row in pop_data:
    if (data_row['Year'] == '2010'):
        country_name = data_row['Country Name']
        #we need to convert string into float first
        #after that int() function can remove decimal
        country_code = get_country_code(country_name)
        population = int(float(data_row['Value']))
        if country_code:
            cc_population[country_code] = population
            print(country_code + ": " + str(population))
        else:
            print("ERROR - " + country_name)
        #print(country_name + " : " + str(population))
wm = World()
wm.title = 'World Population 2020 by Country'
wm.add('2010', cc_population)
wm.render_to_file('"world_population.svg"')
#open file
safari = app("Safari")
safari.make(
    new=k.document,
    with_properties={
        k.URL:
        "file:///Users/tungvo/Desktop/Portfolio/data_analysis/world_population.svg"
    })
Ejemplo n.º 7
0
    # Group the countries into 3 IMF-credit levels;
    # this time, we need a separate "n/a" level for countries
    # where values were unavailable.
    imf_credit_n, imf_credit_1, imf_credit_2, imf_credit_3 = {}, {}, {}, {}
    for cc, imf_credit in cc_imfcredits.items():
        # none_to_zero needed because pygal skips None's, when plotting
        if imf_credit == None:
            imf_credit_n[cc] = none_to_zero(imf_credit)
        elif imf_credit < 1000000000:  # x < 1B
            imf_credit_1[cc] = imf_credit
        elif imf_credit < 10000000000:  # 1B <= x < 10B
            imf_credit_2[cc] = imf_credit
        else:  # 10B <= x
            imf_credit_3[cc] = imf_credit

    # See how many countries are in each level.
    print(len(imf_credit_n), len(imf_credit_1), len(imf_credit_2),
          len(imf_credit_3))

    # Plot the data.
    wm_style = RS('#336699')
    wm = World(style=wm_style)
    wm.title = 'Use of IMF Credit in 2010 (in USD), by Country'
    wm.add('n/a', imf_credit_n)
    wm.add('0-1bn', imf_credit_1)
    wm.add('1bn-10bn', imf_credit_2)
    wm.add('>10bn', imf_credit_3)

    wm.render_to_file('use_of_imf_credit.svg')
Ejemplo n.º 8
0
filename = 'population_data.json'
with open(filename) as f:
    pop_data = json.load(f)

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

cc1, cc2, cc3 = {}, {}, {}
for cc, popu in cc_populations.items():
    if popu < 10000000:
        cc1[cc] = popu
    elif popu < 1000000000:
        cc2[cc] = popu
    else:
        cc3[cc] = popu

wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = 'Population in world'
wm.add('< 10m', cc1)
wm.add('10m - 1b', cc2)
wm.add('> 1b', cc3)
wm.render_to_file('world_populations_new.svg')
Ejemplo n.º 9
0
def get_country_code(country_name):
	for code, name in COUNTRIES.items():
		
		if name == country_name:
			return code
	return None
gdps = r.json()
gdps_lys = []
for gdp in gdps:
	if len(gdps_lys) == 0:
		gdps_lys.append({'name': gdp['Country Name'], 'year': gdp['Year'],'value': gdp['Value']})
	else:
		if gdps_lys[-1]['name'] == gdp['Country Name']:
			gdps_lys[-1]['year'] = gdp['Year']
			gdps_lys[-1]['value'] = gdp['Value']
		else:
			gdps_lys.append({'name': gdp['Country Name'], 'year': gdp['Year'],'value': gdp['Value']})
countries = {}
ans = 0
for gdp in gdps_lys:
	code = get_country_code(gdp['name'])
	if code:
		countries[code] = gdp['value']*1000000000
	else:
		print(gdp['name'])
print (ans)
wm = World()
wm.title = 'Gpd of counries'
wm.add('',countries)
wm.render_to_file('Gdps.svg')
Ejemplo n.º 10
0
for gdp_dict in gdp_data:
    if gdp_dict['Year'] == 2016:
        country_name = gdp_dict['Country Name']
        value = int(gdp_dict['Value'])
        code = get_country_code(country_name)
        if code:
            values[code] = value

# Value levels.
cc_value_1, cc_value_2, cc_value_3 = {}, {}, {}
for c, v in values.items():
    if v < 100000000000:
        cc_value_1[c] = v
    elif v < 1000000000000:
        cc_value_2[c] = v
    else:
        cc_value_3[c] = v

# Prints numerical value of the three categories of GDP.
print(len(cc_value_1), len(cc_value_2), len(cc_value_3))

wm = World()
wm.title = "World Gross Domestic Product in 2016, by country"
# Keeps value from being scientific notation.
wm.value_formatter = lambda x: "{:,}".format(x)
wm.add('< 100B', cc_value_1)
wm.add('100B - 1T', cc_value_2)
wm.add('> 1T', cc_value_3)

wm.render_to_file('world_gdp_2016.svg')
Ejemplo n.º 11
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

# 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 < 10000000:
        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_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
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('../img/world_population.svg')
Ejemplo n.º 12
0
#
#       Plotando mapas das américas
#

from pygal.maps.world import World

wm = World()
wm.title = 'North, Centra, 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('data/americas.svg')

#       Criamos uma instância da classe 'World()' e definimos o atributo 'title'
#       do mapa. Em seguida usamos o método 'add()', que aceita um rótulo e uma
#       lista de código de países que queremos destacar. Cada chamada a 'add()'
#       define uma nova cor para o ocnjunto de países e acrescenta essa cor a uma
#       legenda à esquerda da imagem, com o rótulo especificado nessa chamada.
        else:
            lf_data[country_name] = lf_value

cc_lf = {}
for country, value in lf_data.items():
    code = get_country_code(country)
    if code:
        cc_lf[code] = value
    else:
        print('ERROR - ' + country_name)

cc_lf_1, cc_lf_2, cc_lf_3 = {}, {}, {}
for key, value in cc_lf.items():
    if value < 5000000:
        cc_lf_1[key] = value
    elif value < 50000000:
        cc_lf_2[key] = value
    else:
        cc_lf_3[key] = value

print(len(cc_lf_1), len(cc_lf_2), len(cc_lf_3))

wm_style = RotateStyle('#556677', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = 'Labor force by Country (year: 2010)'
wm.add('0-5m', cc_lf_1)
wm.add('5m-50m', cc_lf_2)
wm.add('>50m', cc_lf_3)

wm.render_to_file('world_labor_force.svg')
Ejemplo n.º 14
0
# Open file and extract data
filename = "life_female.csv"

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

    # Get to the proper column line on the csv
    for n in range(1, 6):
        next(lifedata)

    # Make a new dictionary. Translate the country names
    # to country_codes, and put them in as keys and the
    # life expectancy data as values (taken from the 2014 data set)
    lrates = {}
    for rowdata in list(lifedata):
        ccode = get_country_code(rowdata[0])
        try:
            lrates[ccode] = float(rowdata[58])
        except ValueError:
            continue

# Plot new graph and output to file
wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
wm.title = 'Female Life Expectancy in 2014, by Country'

wm.add('Years', lrates)

wm.render_to_file('female_mortality.svg')
Ejemplo n.º 15
0
 def map_data(self, user_selection):
     #This object will be used to call one method from the support class.
     support = Support()
     data = pd.read_csv('Kaggle.csv')
     #These two lists will hold all of my data for what the user wants to
     #look at.
     data_list = []
     state_list = []
     info = data[user_selection]
     state = data['State']
     #I am now looping through the data and then appending that information
     #into the list that I created above.
     for i in info:
         data_list.append(i)
     for s in state:
         state_list.append(s)
     #Function to convert country names to 2 letter abbreviations. See country_name_convert function in the
     #support.py file to see how it works. It is the only piece of code that I got all from stack overflow.
     country_codes = support.country_name_convert(state_list)
     #Another list is created to hold all of the country abbreviations which have been converted to lowercase.
     new_countrylist = []
     #I have to convert all of the country codes to lowercase-only way the wm.add method seems to work.
     for country in country_codes:
         lowercase_country = country.lower()
         new_countrylist.append(lowercase_country)
     #The wm.add method needs a dictionary to work with. Here, I create a dictionary which holds the country abbrevation
     #and the data for what the user wants to look at.
     country_dictionary = {}
     count = 0
     while count < len(country_codes):
         country_dictionary[new_countrylist[count]] = data_list[count]
         count += 1
     data_1, data_2, data_3, data_4, data_5 = {}, {}, {}, {}, {}
     #I need to break up the data points into five different intervals.
     #To do this I need to find the max and min of the data_list
     max_value = max(data_list)
     min_value = min(data_list)
     #Once I have the max and min I can find the length
     length = max_value - min_value
     #I then divide the length by 5 for the number of dictionaries that I
     #have created above: data_1, data_2 etc.
     parts = length / 5
     #I use a for loop to place the data into the right intervals
     for state, information in country_dictionary.items():
         if information <= parts:
             data_1[state] = information
         elif information > parts and information <= parts * 2:
             data_2[state] = information
         elif information > parts * 2 and information <= parts * 3:
             data_3[state] = information
         elif information > parts * 3 and information <= parts * 4:
             data_4[state] = information
         else:
             data_5[state] = information
     print('''
     Please note to look at the data, you have to open up the SVG map in
     Chrome. The file should be entitled map.svg. The program will return to
     the main menu so you must open up the file manually.
     ''')
     input('Press enter to continue ')
     #This code here is what will actually make the SVG maps for the data that
     #the user wants to look at.
     wm_style = RotateStyle('#336699')
     wm = World(style=wm_style)
     wm.title = "Map of " + user_selection + ' Data'
     wm.add(str(0) + '-' + str(parts), data_1)
     wm.add(str(parts) + '-' + str(parts * 2), data_2)
     wm.add(str(parts * 2) + '-' + str(parts * 3), data_3)
     wm.add(str(parts * 3) + '-' + str(parts * 4), data_4)
     wm.add(str(parts * 4) + '-' + str(parts * 5), data_5)
     wm.render_to_file('map.svg')
Ejemplo n.º 16
0
from pygal.maps.world import World

wm = World()
wm.force_uri_protocol = 'http'
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')
# Load the data into a list.
filename = 'gdp.json'
with open(filename) as f:
    # Changed pop_data to gdp_data
    gdp_data = json.load(f)

# Print the GDP for each country.
# Building a dictionary for GDP data.
cc_gdp = {}
for gdp_dict in gdp_data:
    if gdp_dict['Year'] == 2016:
        country_name = gdp_dict['Country Name']
        gdp_value = int(float(gdp_dict['Value']))
        code = get_country_code(country_name)
        if code:
            cc_gdp[code] = gdp_value
        # Prints Error value keypairs
        #     print(code + ": " + str(gdp_value))
        # else:
        #     print('ERROR - ' + country_name)

        # print(country_name + ": " + str(gdp_value))

wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
wm.title = 'Gross Domestic Product in 2016, by Country'
wm.add('2016', cc_gdp)

wm.render_to_file('gross_domestic_product.svg')
Ejemplo n.º 18
0
filename = 'population_data.json'
with open(filename) as f:
	pop_data = json.load(f)
	cc_population={}
	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_population[code] = population
			
	cc_pop1, cc_pop2, cc_pop3 = {},{},{}
	for code, pop in cc_population.items():
		if pop < 10000000:
			cc_pop1[code] = pop
		else: 
			if pop < 1000000000:
				cc_pop2[code] = pop
			else:
				cc_pop3[code] = pop
	print(len(cc_pop1),len(cc_pop2),len(cc_pop3))
	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_pop1)
	wm.add('10-1bn',cc_pop2)
	wm.add('>1bn',cc_pop3)
	wm.render_to_file('world.svg')
	
            population_data_2010.append(record)
        else:
            print("Error: " + record["Country Name"] + " is invalid")

# store in dictionary to be worked with pygal
# pops_1: population < 10000000
# pops_2: 10000000 <= population <= 1000000000
# pops_3: population > 1000000000
pops_1, pops_2, pops_3 = {}, {}, {}

for record in population_data_2010:
    cc = find_country_code(record["Country Name"])
    population = int(float(record["Value"]))
    if population < 10000000:
        pops_1[cc] = population
    elif population <= 1000000000:
        pops_2[cc] = population
    else:
        pops_3[cc] = population

# plot
world_population_map = World()
world_population_map.title = 'World Population Map'

world_population_map.add('< 10m', pops_1)
world_population_map.add('10m - 1bn', pops_2)
world_population_map.add('>1bn', pops_3)

world_population_map.render_to_file(
    'World Population Map (grouping countries by population).svg')
cc_expenditure = {}

with open("education.csv") as file:
    reader = csv.reader(file)

    #count=0

    for row in reader:

        if row[-6]:
            dic[row[0]] = row[-6]

        #print(row[-6]) # 2014 year

        #print(len(row))
        #if count > 100:
        #    break

        #count +=1

    for country, expenditure in dic.items():
        code = get_country_code(country)

        if code:
            cc_expenditure[code] = int(float(expenditure))

wm = World()
wm.title = 'World Governments expenditure on education'
wm.add('2014', cc_expenditure)
wm.render_to_file('world_expenditure.svg')
Ejemplo n.º 21
0
from pygal.maps.world 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.html')
Ejemplo n.º 22
0
    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
        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 < 10000000:
        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_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("data visualization/world_population.svg")
Ejemplo n.º 23
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


# 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 < 10000000:
        cc_pops_1[cc] = pop
    elif pop < 1000000000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop

# Plot and output to file
wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
wm.title = 'World Population in 2010, by Country'

wm.add('0-10m', cc_pops_1)
wm.add('10-1bn', cc_pops_2)
wm.add('>1bn', cc_pops_3)

wm.render_to_file('world_poulations.svg')
Ejemplo n.º 24
0
import pygal
from pygal.maps.world import World


wm = World()
wm.title = 'Populations of Countries in North America'
wm.add('North America', {'ca': 341260000, 'us': 309349000, 'mx': 113423000})
wm.render_to_file('North America Population.svg')

Ejemplo n.º 25
0
#
#       Plota dados básico no mapa mundi
#

from pygal.maps.world 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('data/populacao_americana.svg')


#       Desta vez, ao utilizar método 'add()', passamos um dicionário como segundo
#       argumento em vez de passar uma lista. O dicionário contém os códigos de
#       duas letras do Pygal para os países como chave e as populações como
#       valores. O pygal utiliza automaticamente esses números para sombrear os
#       países, variando da cor mais clara (menos populoso) para a cor mais escura
#       (mais populoso).
Ejemplo n.º 26
0
from pygal.maps.world 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')
Ejemplo n.º 27
0
        if name == country:
            return code
    return None


file_name = 'API_NY.GDP.PCAP.KD.ZG_DS2_en_csv_v2_10134495.csv'
with open(file_name) as f:
    reader = csv.reader(f)
    next(reader)
    next(reader)
    next(reader)
    next(reader)
    for index, name in enumerate(next(reader)):
        print(index, name)
    country_gdp = {}
    for row in reader:
        try:
            country = row[0]
            year = float(row[61])
            code = get_code(country)
            if code:
                country_gdp[code] = year
        except ValueError:
            pass

wm_style = RS('#993366')
wm = World(style=wm_style)
wm.title = 'World GDP per capita increase'
wm.add('2017', country_gdp)
wm.render_to_file('images/gdp_growth.svg')
Ejemplo n.º 28
0
        if code:
            print(code + ": " + str(population))
        else:
            print('ERROR - ' + country_name)

        if code:
            cc_population[code] = population

#Group the countries into 3 population levels
cc_pops1, cc_pops2, cc_pops3, cc_pops4 = {}, {}, {}, {}
for cc, pops in cc_population.items():
    if pops < 1000000000:
        cc_pops1[cc] = pops
    elif 1000000001 <= pops <= 100000000000:
        cc_pops2[cc] = pops
    elif 100000000001 <= pops < 100000000000000:
        cc_pops3[cc] = pops
    else:
        cc_pops4[cc] = pops

#Plot the map
wm_style = RotateStyle('#990099')
wm = World(style=wm_style)
wm.title = 'GDP in 2010, by Country'
wm.add('0-1bn', cc_pops1)
wm.add('1bn-100bn', cc_pops2)
wm.add('100bn-1tr', cc_pops3)
wm.add('>1tr', cc_pops4)
wm.render_to_file('world_gdp_a.svg')
        country_code = get_country_code(
            country_name)  #standardize country code for each country
        population = int(
            float(data_row['Value'])
        )  #we need to convert string into float first after that int() function can remove decimal
        if country_code:
            if population < 10000000:
                cc_pop1[country_code] = population
            elif population < 1000000000:
                cc_pop2[country_code] = population
            else:
                cc_pop3[country_code] = population
            print(country_code + ": " + str(population))
        else:
            print("ERROR - No Country Code Found " + country_name)
        #print(country_name + " : " + str(population))
style_obj = RS('#0000FF', base_style=LCS)  #return an object of style
wm = World(style=style_obj)
wm.title = 'World Population 2020 by Country'
wm.add('0-10m', cc_pop1, c="blue")
wm.add('10m-1b', cc_pop2, c="yellow")
wm.add('>1b', cc_pop3, c="red")
wm.render_to_file("three_basket_world_population_new_style.svg")
#open pygal file with Safari
safari = app("Safari")
safari.make(
    new=k.document,
    with_properties={
        k.URL:
        "file:///Users/tungvo/Desktop/Portfolio/data_visualization/three_basket_world_population_new_style.svg"
    })
Ejemplo n.º 30
0
for code, pop in cc_population.items():
    if pop < 10000000:
        pop1[code] = pop
    elif pop < 50000000:
        pop2[code] = pop
    elif pop < 100000000:
        pop3[code] = pop
    elif pop < 150000000:
        pop4[code] = pop
    elif pop < 500000000:
        pop5[code] = pop
    else:
        pop6[code] = pop

wm_style = RS('#336699')
wm = World(style=wm_style)
wm.title = 'World population for 2010 by Country'
wm.add('2010', cc_population)
wm.render_to_file('images/w_pop_2010.svg')

wm_style = RS('#336699', base_style=LS)
wm = World(style=wm_style)
wm.title = 'WP - 2010 - per groups'
wm.add('<10m', pop1)
wm.add('10m-50m', pop2)
wm.add('50m-100m', pop3)
wm.add('100m-150m', pop4)
wm.add('150m-500m', pop5)
wm.add('>1b', pop6)
wm.render_to_file('images/wp_2010_groups.svg')
Ejemplo n.º 31
0
def store_pib_info(country_infos, countries_pib):
    if country_infos['Year'] == 2014:
        country_name = country_infos['Country Name']
        pib = country_infos['Value']
        country_code = get_country_code(country_name)

        if country_name:
            countries_pib[country_code] = pib


def get_countries_pib():
    with open(filename, 'r') as file:
        countries_infos = json.load(file)

    countries_pib = dict()

    for country_infos in countries_infos:
        store_pib_info(country_infos, countries_pib)

    return countries_pib


hex_color = '#300011'
wm_style = RotateStyle(hex_color)

wm = World(style=wm_style)
wm.title = 'PIB in 2014, by country'
wm.add('2014', get_countries_pib())
wm.render_to_file('pib.svg')
Ejemplo n.º 32
0
    cc_gdp = {}
    for gdp_dict in gdp_data:
        if gdp_dict['Year'] == '2010':
            country_name = gdp_dict['Country Name']
            gdp = int(float(gdp_dict['Value']))
            code = get_country_code(country_name)
            if code:
                cc_gdp[code] = gdp

# Group the countries into 3 gdp levels.
cc_gdp_1, cc_gdp_2, cc_gdp_3 = {}, {}, {}
for cc, gdp in cc_gdp.items():
    if gdp < 1000000000:
        cc_gdp_1[cc] = gdp
    elif gdp < 10000000000000:
        cc_gdp_2[cc] = gdp
    else:
        cc_gdp_3[cc] = gdp

# Plot and output to file
wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
wm.title = 'World GDP in 2010, by Country'

wm.add('0-1bn', cc_gdp_1)
wm.add('1bn-1tr', cc_gdp_2)
wm.add('>1tr', cc_gdp_3)

wm.render_to_file('world_gdp.svg')
Ejemplo n.º 33
0
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop

#   Vê quantos países estão em cada nível
print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3))

#   Cria o mapa
wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = 'World Populations 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('data/estilizando_mapa_mundi.svg')


#       Os estilos do Pygal estão armazenados no módulo 'style' do qual importamos
#       o estilo 'RotateStyle'. Essa classe aceita um argumento, que é uma cor RGB
#       em formato hexa. O Pygal então escolhe as cores para cada um dos grupos de
#       acordo com a cor fornecida.
#
#       'RotateStyle' devolve um objeto estilo, que armazenamos em 'wm_style'. Para
#       usar esse objeto, passe-o como um argumento nomeado ao criar uma instância
#       de 'World'.
#
#       O Pygal tende a usar temas escuros por padrão. Para deixar os mapas mais
#       claros, use a classe 'LightColorizedStyle'. Essa classe altera o tema do
#       mapa como um todo, incluindo a cor de fundo e os rótulos, assim como as 
#       cores individuais dos países. No entanto, essa classe não oferece nenhum
Ejemplo n.º 34
0
from pygal.maps.world import World

wm = World()
wm.title = 'Populations of Countries in North America'
wm.add("North America", {"ca":3412600, 'us': 309349000, 'mx': 113423000})

wm.render_to_file("C:\\Users\\Asymmetry\\Desktop\\na_populations.svg")
Ejemplo n.º 35
0
from pygal.maps.world 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")
Ejemplo n.º 36
0
#
from pygal.maps.world 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')
Ejemplo n.º 37
0
import pygal
import pygal_maps_world
#import base64
from pygal.maps.world import World
#from ipywidgets import HTML
from flask import Flask
from flask import request

print("1")
if request.method == 'POST':
    print("1")
    countryCode = request.form['code']
else:
    print('No country code entered!')

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

wm.title = "Women Political leader distribution across countries"
wm.add('Leaders', {'ca': 4, 'mx': 1, 'us': 6})
#wm.chart.render()
wm.render_to_file('map.svg')
#b64 = base64.b64encode(wm.render())
#src = 'data:image/svg+xml;charset=utf-8;base64,'+b64
#HTML('<embed src={}></embed>'.format(src))