コード例 #1
0
def rendermap():
    message = ''
    result = ''
    leaderitems = {}
    cc = ''
    logging.info("POST request path /rendermap")
    if request.method == 'POST':
        cc = request.form.get('countryCode')
        if cc == '':
            message = "Please enter a 2 letter ISO country code"
        cc = cc.lower()
        ccupper = cc.upper()
        logging.info("ISO country code entered:" + cc)

        #Load the country json
        with open('data/leaders.json') as leaders_json_file:
            leadersdata = json.load(leaders_json_file)
            #for w in leadersdata:
            #    print("%s: %d" % (w, leadersdata[w]))
            if ccupper not in leadersdata:
                message = "Wrong country code. Click Home link and enter a valid 2-letter ISO code!"
            else:
                leaderitems[cc] = float(leadersdata[ccupper])
                result = cc + ":" + str(leadersdata[ccupper])
                with open('data/neighbours.json') as neighbours_json_file:
                    nd = json.load(neighbours_json_file)
                    #for n in nd:
                    #    print("%s: %s" % (n, str(nd[n])))
                    narr = nd[cc]
                    for neighbour in narr:
                        nupper = neighbour.upper()
                        if nupper in leadersdata:
                            leaderitems[neighbour] = float(leadersdata[nupper])
                            result += "," + str(neighbour) + ":" + str(
                                leadersdata[nupper])
                        else:
                            message += "Data not available for neighbouring country ISO Code:" + str(
                                neighbour) + "\n"

                #Create world map with result
                wm_style = RotateStyle('#34126000')
                wm = World()
                wm.force_uri_protocol = 'http'

                wm.title = "Women Political leaders (%)"
                wm.add('', leaderitems)
                wm.render_to_file('templates/lmap.svg')
                svg = render_template('lmap.svg')

    print("Result " + result)
    print("Message " + message)
    print(len(leaderitems))
    #svgf = open("templates/lmap.svg", "r").read()
    #svg_io = StringIO()
    #svg_io.write(svgf)
    #svg_io.seek(0)
    #return send_file(svg_io, mimetype='image/svg+xml')
    img = './static/lmap.svg'

    return render_template('leadersmap.html', message=message, img=img)
コード例 #2
0
def view_world_map():
   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')
コード例 #3
0
def world_country_map():
    """绘制世界地图"""
    wm_c = World()
    # wm_c.force_url_protocol = 'http'
    wm_c.title = 'World Map'
    for code, name in COUNTRIES.items():
        wm_c.add(name, code)

    wm_c.add('Yemen', {'ye': 'Yemen'})
    wm_c.render_to_file('world_map.svg')
コード例 #4
0
ファイル: c16e07birthRate.py プロジェクト: rarog2018/PythonCC
def main():
    # collect the data from a given file and store it in a dictionary
    birthRate = collect_birth_rate_data("birth_rate.csv")

    # Create a map and fill it with data
    wm = World()
    wm.title = "Countries birth rate, 2018"
    wm.add("birth rates", birthRate)

    wm.render_to_file('world_birth_rate.svg')
コード例 #5
0
 def GET(self):
     user_data = web.input()
     prd = user_data.product
     pg = user_data.data
     from pygal.maps.world import World
     wm = World(height=400)
     wm.force_uri_protocol = 'http'
     wm.title = "產品 " + prd + " 的 " + pg + " 在全球即時分佈的狀態"
     d = getlist(prd, pg)
     i = 0
     for item in d:
         x = {}
         x[incl.countrycode[item[0]]] = item[1]
         wm.add(str(i + 1) + ". " + item[0], x)
         i = i + 1
     #wm.render_to_file("static/map.svg")
     wm.disable_xml_declaration = True
     return '<html>\n        <head>\n                <title>全球即時分佈圖</title>\n<meta http-equiv="content-type" content="text/html;charset=utf-8"><meta http-equiv="refresh" content="30" />\n<script type="text/javascript" src="http://kozea.github.com/pygal.js/latest/pygal-tooltips.min.js"></script>\n</head>\n<body>\n' + wm.render(
         is_unicode=True) + '\n </body>\n</html>'
コード例 #6
0
def make_world_map():
    # Load the data into a list
    filename = 'population_data.json'
    with open(filename) as f:
        pop_data = json.load(f)
    # Get the two digits cuntries codes
    codes_and_names = get_country_list()
    # Build a dictionary of population data
    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, codes_and_names)
            if code:
                cc_populations[code] = population
    # Make world map
    wm = World()
    wm.title = 'World population in 2010, by Country'
    wm.add('2010', cc_populations)
    # Convert it to file
    wm.render_to_file("world_population.svg")
コード例 #7
0
def draw_word_map(prob_predict: List[float],
                  countries: List[str],
                  output_file: str = 'word_map.svg'):
    """
    > 0.5 accending => prob
    < 0.5 descending => 1 - prob
    """
    worldmap_chart = World()
    worldmap_chart.title = 'World Map'
    accending = {}
    descending = {}
    for prob, country in zip(prob_predict, countries):
        country_code = get_country_code(country)
        if not country_code:
            continue

        if prob > 0.5:
            accending[country_code] = prob
        else:
            descending[country_code] = prob

    worldmap_chart.add('accending', accending)
    worldmap_chart.add('descending', descending)
    worldmap_chart.render_to_file(output_file)
コード例 #8
0
for pop_dict in pop_data:
    if pop_dict['Year'] == '2015':
        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:
            #print(code + ": " + str(population))
            cc_populations[code] = population
        # else:
        #     print('ERROR - ' + country_name)
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=LS)
#wm_style = LightStyle
wm = World(style=wm_style)
wm.title = "World Population in 2015, by Country"
#wm.add('2015',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')
コード例 #9
0
import pygal
from pygal.maps.world import World

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

wm.add('North America', ['ca', 'mx', 'us'])
wm.add('Canral 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')
コード例 #10
0
from pygal.style import RotateStyle, LightColorizedStyle

# 根据用电量的范围分组, 统计数据到{国别码: 用电量}6个字典里
group1, group2, group3, group4, group5, group6 = {}, {}, {}, {}, {}, {}
for name, used in zip(country_names, eletri_used):
    code = get_country_code(name)
    if used > 20000:
        group1[code] = used
    elif used > 8000:
        group2[code] = used
    elif used > 3000:
        group3[code] = used
    elif used > 500:
        group4[code] = used
    elif used != 0:
        group5[code] = used
    else:
        group6[code] = used

# 着色,加亮颜色主题
wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = title
wm.add('>20th', group1)
wm.add('20th-8th', group2)
wm.add('3th-8th', group3)
wm.add('0.5th-3th', group4)
wm.add('0-0.5th', group5)
wm.add('0', group6)
wm.render_to_file('power_used.svg')
コード例 #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

# Podzielenie 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

# Wyświetlenie liczby państw w każdej z trzech grup.        
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 = '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')
コード例 #12
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')
コード例 #13
0
filename = 'gdp.json'
with open(filename) as f:
    gdp_data = json.load(f)

cc_gdp = {}
for gdp_dict in gdp_data:
    if gdp_dict['Year'] == 2016:
        country_name = gdp_dict['Country Name']
        gdp = int(float(gdp_dict['Value']))
        code = country_codes.get_country_code(country_name)
        if code: 
            cc_gdp[code] = gdp
        else:
            print(country_name + " has no code.")

cc_gdp_1, cc_gdp_2 = {}, {}

for cc, gdp in cc_gdp.items():
    if gdp < 1000000000000:
        cc_gdp_1[cc] = gdp
    else:
        cc_gdp_2[cc] = gdp

wm_style = RotateStyle('#336699')
wm = World(style=wm_style)
wm.title = "GDP in 2016, by Country"
wm.add('0-1tr', cc_gdp_1)
wm.add('>1tr', cc_gdp_2)

wm.render_to_file('world_gdp.svg')
コード例 #14
0
ファイル: na_populations.py プロジェクト: alibabaz/crash
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')
コード例 #15
0
from pygal.maps.world import COUNTRIES, World
import pygal


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


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

wm.add('North America', {'ca': 34126000, 'us': 309349000, 'mx': 113423000})
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('america.svg')
コード例 #16
0
# Build a dictionary of population data in 2010.
for pop_dict in population_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

# Store countries in 3 groups according to population number
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

wm_style = RS('#336699', base_style=LCS)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
wm.title = 'Populacja na świecie w 2010 r. (dane dla poszczególnych państw)'
wm.add('0-10 mln', cc_pops1)
wm.add('10 mln - 1 mld', cc_pops2)
wm.add('> 1 mld', cc_pops3)

wm.render_to_file('world_population.svg')

コード例 #17
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

# Podzielenie 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

# Wyświetlenie liczby państw w każdej z tzech grup
print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3))

wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.force_uri_protocol = 'http'
wm.title = 'Populacja na świecie w 2010 roku'
wm.add('0 - 10 mln', cc_pops_1)
wm.add('10 - 1 mld', cc_pops_2)
wm.add('>1 mld', cc_pops_3)

wm.render_to_file('world_population.svg')
コード例 #18
0
# Plot population data on the world map.

from pygal.maps.world import World

wm = World()
wm.title = "North American Populations"

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

wm.render_to_file('files/north_america.svg')
コード例 #19
0
from pygal.maps.world import World

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

wm.render_to_file('na_populations.svg')
コード例 #20
0
from pygal.maps.world import World

wm = World()
wm.title = 'North, Central amd 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')
コード例 #21
0
ファイル: gdp.py プロジェクト: pbrownlee/pyprojects
    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')
コード例 #22
0
        if country == countryName:
            return code
    return None


with open("population_data.json") as file:
    contents = json.load(file)

populations1, populations2, populations3 = {}, {}, {}
for dict in contents:
    if dict['Year'] == '2010':
        code = getCountryCode(dict['Country Name'])
        if code:
            population = int(float(dict['Value']))
            if population < 10000000:
                populations1[code] = population
            elif population < 100000000:
                populations2[code] = population
            else:
                populations3[code] = population

mapStyle = RS("#0088ff", base_style=LCS)
map = World(style=mapStyle)
map.title = "2010 Populations"

map.add("0-10m", populations1)
map.add("10-100m", populations2)
map.add("100m+", populations3)

map.render_to_file("populationMap.svg")
コード例 #23
0
#now we create a worldmap of Continents
# like SA,NA,CA,ASIA

from pygal.maps.world import World

wm = World()

#wm.force_uri_protocol = 'http'
wm.title = 'North, Central, and South America,Asia,Arab'

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.add("Asia", ["in", "jp", "cn", "id", "th", "sg"])
wm.add("Arab", ["eg", "iq", "dz", "bh", "jo", "sa", "ae"])
wm.render_to_file('americas.svg')
コード例 #24
0
    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
            else:
                print('Error-' + country_name)

    cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
    #group populations into categorys
    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 = RotateStyle('#336699')
    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('world_populations.svg')
コード例 #25
0
from pygal.maps.world import World

wm = World()
wm.force_uri_protocol = 'http'
wm.title = 'Ameryka Północna, Środkowa i Południowa'
wm.add('Ameryka Północna', ['ca', 'mx', 'us'])
wm.add('Ameryka Środkowa', ['bz', 'cr', 'gt', 'hn', 'ni', 'pa', 'sv'])

wm.add('Ameryka Południowa', [
    'ar', 'bo', 'br', 'cl', 'co', 'ec', 'gf', 'gy', 'pe', 'py', 'sr', 'uy',
    've'
])
wm.render_to_file('americas.svg')
コード例 #26
0
    if gdp_dict['Year'] == '2014':
        country_name = gdp_dict['Country Name']
        gdp = int(float(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')
コード例 #27
0
from pygal.maps.world import World

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

wm.render_to_file('na_population.svg')
コード例 #28
0
ファイル: americas.py プロジェクト: nflondo/myprog
#
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')
コード例 #29
0
from pygal.maps.world import World

wm = World()
wm.title = 'Population in North America'
wm.add('North America', {'ca': 34126000, 'us': 309349000, 'mx': 113423000})
wm.render_to_file('na_population.svg')
コード例 #30
0
        if gdb_dict['Year'] == '2014':
            country_name = gdb_dict['Country Name']
            gdb_value = float(gdb_dict['Value'])
            code = get_country_code(country_name)
            if code:
                cc_gdb[code] = gdb_value
            else:
                print('ERROR - ' + country_name)

cc_gdb_1, cc_gdb_2, cc_gdb_3, cc_gdb_4 = {}, {}, {}, {}
for cc, gdb in cc_gdb.items():
    if gdb < 10000000000:
        cc_gdb_1[cc] = gdb
    elif gdb < 100000000000:
        cc_gdb_2[cc] = gdb
    elif gdb < 1000000000000:
        cc_gdb_3[cc] = gdb
    else:
        cc_gdb_4[cc] = gdb

print(len(cc_gdb_1), len(cc_gdb_2), len(cc_gdb_3), len(cc_gdb_4))

wm_style = RotateStyle('#663399', base_style=LightColorizedStyle)
wm = World(style=wm_style)
wm.title = 'GDB in USD($) for world countries for year 2014'
wm.add('GDB: 0-10b', cc_gdb_1)
wm.add('GDB: 10b-100b', cc_gdb_2)
wm.add('GDB: 100b-1000b', cc_gdb_3)
wm.add('GDB: >1000b', cc_gdb_4)

wm.render_to_file('world_gdb.svg')
コード例 #31
0
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

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

wm_style = RS('#336699', base_dtyle=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')
コード例 #32
0
from pygal.maps.world import World
wm = World()
wm.title = 'North, Center, and South America'

wm.add('North America', ['ca', 'mx', 'us'])
wm.add('Center 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')
コード例 #33
0
ファイル: na_populations.py プロジェクト: ZanW/Python
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")
コード例 #34
0
for pop_dict in pop_data:
    if pop_dict['Year'] == 2016:
        country = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        code = get_country_code(country)
        if code:
            cc_populations[code] = population

# Group the countries into 3 population levels
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 1000000000 > pop > 10000000:
        cc_pop_2[cc] = pop
    else:
        cc_pop_3[cc] = pop
# See how many countries are in each level
print(len(cc_pop_1), len(cc_pop_2), len(cc_pop_3))

wm = World()
wm_style = RotateStyle('#336699', base_style=LightColorizedStyle)
wm.force_uri_protocol = 'http'
wm.title = 'World Population in 2016, by Country'
wm.add('0-10m', cc_pop_1)
wm.add('10m-1bn', cc_pop_2)
wm.add('>1b', cc_pop_3)

wm.render_to_file('world_population.svg')

コード例 #35
0
    # json.load() converts the data into a format Python can work with
    pop_data = json.load(f)

# build a dictionary of population data
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

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

wm = World()
wm.force_uri_protocol = 'http'
wm.title = 'World Population in 2010, by Country'
wm.add('0-10,', cc_pops_1)
wm.add('10m-1bn', cc_pops_2)
wm.add('>1bn', cc_pops_3)
wm.render_to_file('world_population.svg')
コード例 #36
0
ファイル: americas.py プロジェクト: alibabaz/crash
from pygal.maps.world import World

wm = World()
wm.title = "North, Center & South America"

wm.add('North America', ['ca', 'mx', 'us'])
wm.add('Center 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')
コード例 #37
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')
コード例 #38
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')
コード例 #39
0
from pygal.maps.world import World

wm = World()
wm.force_uri_protocol = 'http'
wm.title = 'Wielkość populacji w krajach Ameryki Północnej'
wm.add('Ameryka Północna', {'ca': 34126000, 'us': 309349000, 'mx': 113423000})

wm.render_to_file('na_populations.svg')