def conlanger_map(): foo = dict([(country.iso.lower(), country.count) for country in country_most_common()]) custom_style = Style( background='#fff', plot_background='#fff', foreground='#ffffff', foreground_light='#ffffff', foreground_dark='#ffffff', opacity='.6', opacity_hover='.9', transition='400ms ease-in', colors=('#527C3A', '#E8537A', '#E95355', '#E87653', '#E89B53') ) chart = Worldmap(style=custom_style) chart.no_prefix = True chart.disable_xml_declaration = True chart.show_legend = False chart.add('Conlangers', foo) return chart.render()
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')
# 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')
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')
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', 'sr', 'uy', 've']) wm.render_to_file('americas.svg')
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')
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")
from pygal.maps.world import World wm = World() wm.force_uri_protocol = 'http' 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('americas.svg')
import json from country_codes import get_country_code from pygal.maps.world import World from pygal.style import RotateStyle # Wczytanie danych i umieszczenie ich na liście. filename = 'gdp_json.json' with open(filename) as f: pop_data = json.load(f) # Utworzenie słownika danych dotyczących populacji. cc_populations = {} for pop_dict in pop_data: if str(pop_dict['Year']) == '2010': country_name = pop_dict['Country Name'] population = pop_dict['Value'] code = get_country_code(country_name) if code: cc_populations[code] = float(population) print(cc_populations) wm_style = RotateStyle('#336699') wm = World(style=wm_style) wm.force_uri_protocol = 'http' wm.value_formatter = lambda x: "%.2f" % x wm.add('GDP', cc_populations) wm.render_to_file('world_gdp.svg')
gdp = int(float(pop_dict['Value'])) code = get_country_code(country) if code: cc_gdps[code] = gdp else: print('Error - ', country ) # 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')
import pygal 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',f 'gy', 'pe', 'py', 'sr', 'uy', 've']) wm.render_to_file('americas.svg')
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))
from pygal.maps.world import World wm = World() wm.title = 'North, Central, South America and Ukraine' 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('Ukraine', ['ua']) wm.render_to_file('americas.svg')
from pygal.maps.world import World 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('svg/americas.svg')
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')
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')
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 poplulation 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 = World() wm_style =RotateStyle('#336699') wm = World(style=wm_style) wm.title = 'World Population in 2010, by Country' wm.add('0-10m', cc_pops_1) wm.add('10m-1b', cc_pops_2) wm.add('>1b', cc_pops_3) wm.render_to_file('world_population.svg')
cc_population={} for pop_dict in pop_date:#将每个字典存储在pop_dict中 if pop_dict['Year']=='2010': #for循环是一次操作一个值 country_name=pop_dict['Country Name'] population=int(float(pop_dict['Value'])) code=get_country_code(country_name) if code: cc_population[code]=population #字典的赋值 else: print("ERROR"+":"+country_name) for cc,pop in cc_population.items(): if pop<100000000: cc_pop1[cc]=pop elif pop<1000000000: cc_pop2[cc]=pop else: cc_pop3[cc]=pop 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('10m-1bn',cc_pop2) wm.add('>1bn',cc_pop3) wm.render_to_file('word_population.svg')
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')
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(country_name + " has no code.") # Group the countries into 3 population levels: less than 10 million, less than 1 billion, and more than 1 billion cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {} for country, pop in cc_populations.items(): if pop < 10000000: cc_pops_1[country] = pop elif pop >= 10000000 and pop < 1000000000: cc_pops_2[country] = pop else: cc_pops_3[country] = pop # See how many countries are in each level. print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3)) wm_style = RotateStyle('#00008B') 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')
# 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')
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')
# 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')
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('amrericas.svg')