Beispiel #1
0
def show_east_asia():
    wm_style = RS("#336699", base_style=LCS)
    worldmap_chart = pygal.maps.world.World(style=wm_style)
    worldmap_chart.title = 'East Asia'
    worldmap_chart.add('East Asia', ['cn', 'jp', 'kr'])
    #worldmap_chart.render_in_browser()
    worldmap_chart.render_to_file('east_asia.svg')
def main(args):
    filename = 'population_data.json'
    with open(filename) as f:
        pop_data = json.load(f)

    cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
    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:
                if population < 10000000:
                    cc_pops_1[code] = population
                elif population < 1000000000:
                    cc_pops_2[code] = population
                else:
                    cc_pops_3[code] = population

    wm_style = RS('#336699', base_style=LCS)
    wm = pywm.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')
    return 0
Beispiel #3
0
def year_chart(car_name, year_keys, flat_petrol_y, flat_diesel_y, flat_combo_y,
               unique_years):
    """Create a chart based on the calculated yearly averages."""
    # Define the chart's style
    chart_style = RS('#F7B258', base_style=LCS)

    # Adjust the configuration of the chart
    config = pygal.Config()
    config.x_label_rotation = 45
    config.title_font_size = 24
    config.label_font_size = 12
    config.major_label_font_size = 16
    config.y_labels_major_every = 4

    if len(unique_years) >= 2:
        # Create the chart
        line_chart = pygal.Line(config, style=chart_style, show_legend=True)
        line_chart.title = """Średnie ceny w zależności od roku produkcji i paliwa.
                          Samochód: {}""".format(car_name)
        line_chart.x_labels = year_keys
        line_chart.add('Benzyna', flat_petrol_y)
        line_chart.add('Diesel', flat_diesel_y)
        line_chart.add('Benzyna+LPG', flat_combo_y)
        line_chart.render_to_file('year_prices.svg')

    else:
        bar_chart = pygal.Bar(config, style=chart_style, show_legend=True)
        bar_chart.title = """Średnie ceny w zależności od roku produkcji i paliwa.
                          Samochód: {}""".format(car_name)
        bar_chart.x_labels = year_keys
        bar_chart.add('Benzyna', flat_petrol_y)
        bar_chart.add('Diesel', flat_diesel_y)
        bar_chart.add('Benzyna+LPG', flat_combo_y)
        bar_chart.render_to_file('year_prices.svg')
Beispiel #4
0
def plot(locate):
    wm = pygal.Worldmap()
    wm.title = 'Gdp of 2016'
    wm.add('2016', locate)
    wm_style = RS('#336699', base_style=LCS)

    wm.render_to_file('gdp_2016.svg')
Beispiel #5
0
def show_supranational_world():
    wm_style = RS("#336699", base_style=LCS)
    supra = pygal.maps.world.SupranationalWorld(style=wm_style)
    supra.add('Asia', [('asia', 1)])
    supra.add('Europe', [('europe', 1)])
    supra.add('Africa', [('africa', 1)])
    supra.add('North america', [('north_america', 1)])
    supra.add('South america', [('south_america', 1)])
    supra.add('Oceania', [('oceania', 1)])
    supra.add('Antartica', [('antartica', 1)])
    #supra.render_to_browser()
    supra.render_to_file('supranational_world.svg')
Beispiel #6
0
def get_my_figure(names):
    my_figure = pygal.Config()
    my_figure.style = RS('#114477', base_style=LCS)
    my_figure.show_legend = False
    my_figure.x_label_rotation = 45
    my_figure.title = 'Most stars Python projects of github '
    my_figure.x_labels = names
    my_figure.show_y_guides = False
    my_figure.width = 1000
    my_figure.x_title = 'Name'
    my_figure.y_title = 'Stars Count'
    my_figure.label_font_size = 14
    my_figure.title_font_size = 24
    return my_figure
def plot(year, pop1, pop2='', pop3=''):
    wm_style = RS('#336655')
    wm = pygal.Worldmap(style=wm_style)
    wm.title = 'Population of The World'

    if pop2 and pop3:
        wm.add('0-10m', pop1)
        wm.add('10m-1bn', pop2)
        wm.add('>1bn', pop3)

    else:
        wm.add(year, pop1)

    wm.render_to_file("World Population %s.svg" % year)
Beispiel #8
0
def mileage_chart(car_name, mileage_keys, flat_petrol, flat_diesel,
                  flat_combo):
    """Create a chart based on the calculated mileage range averages."""
    # Define the chart's style
    chart_style = RS('#97C9F2', base_style=LCS)

    # Adjust the configuration of the chart
    config = pygal.Config()
    config.x_label_rotation = 45
    config.title_font_size = 24
    config.label_font_size = 12
    config.major_label_font_size = 16
    config.y_labels_major_every = 4

    # Create the chart
    bar_chart = pygal.Bar(config, style=chart_style, show_legend=True)
    bar_chart.title = """Średnie ceny w zależności od przebiegu i paliwa.
                      Samochód: {}""".format(car_name)
    bar_chart.x_labels = mileage_keys
    bar_chart.add('Benzyna', flat_petrol)
    bar_chart.add('Diesel', flat_diesel)
    bar_chart.add('Benzyna+LPG', flat_combo)
    bar_chart.render_to_file('mileage_prices.svg')
Beispiel #9
0
for pop_dict in pop_data:
    if pop_dict['Year'] == 2016:
        country_name = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        code = get_country_code(country_name)
        # print(country_name + ": " + str(population))
        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('#456789', base_style=LCS)

# 看看每组分别包含多少个国家
wm = pygal.maps.world.World(style=wm_style)
wm.title = 'World Population in 2016, 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')
Beispiel #10
0
    if pop_dict['Year'] == '2010':
        country = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))
        code = get_country_code(country)
        if code:
            cc_populations[code] = population

# Agrupa os países em três níveis populacionais.
cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for cc, pop in cc_populations.items():
    if pop < 10_000_000:
        cc_pops_1[cc] = pop
    elif pop < 1_000_000_000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop

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

w_style = RS('#109008', base_style=LCS)
w = World(style=w_style)
w.title = "World population in 2010, by Country"
w.add('0-10m', cc_pops_1)
w.add('10m-1bn', cc_pops_2)
w.add('>1bn', cc_pops_3)

w.render_to_file(
    'Estudos/PYTHON/Python-VisualizacaoDeDados/Dados-Gráficos/Dowload_de_dados/world_population.svg'
)
Beispiel #11
0
# 打印每个国家2008年的人口数量
for pop_dict in pop_data:
    if pop_dict['Year'] == '2008':
        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)  # 让Pygal使用一种基色
wm = pmw.World(style=wm_style)
wm.title = 'World Population in 2008, 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('diagram/grouped_world_population_2008.svg')
Beispiel #12
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")
for pop_dict in pop_data:
    #print(pop_dict)
    if int(pop_dict['Year']) == 2010:
        country_name = pop_dict['Country Name']
        population = int(pop_dict['Value'])
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population
            #print(code + ": " + str(population))
        else:
            print('ERROR - ' + country_name)
#根据人口数量将所有的国家分成三组
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 < 100000000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop
#看看每组包含了多少个国家
wm = World()
print(len(cc_pops_1),len(cc_pops_2),len(cc_pops_3))
wm_style = RS('#336699', base_style=NS)
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')
    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
            # print(code + ': ' + str(population))
        # else:
        #     print('ERROR - ' + country_name)

# 根据人口数量将所有的国家分成三组
cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for cc, pop in cc_population.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('#337799', base_style=LCS)
wm = World(style=wm_style)
wm.title = 'World Population in 2010 , by Country'
# wm.add('2010', cc_population)
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')
Beispiel #15
0
Сгруппируем страны по 3 уровням населения
1) Менее 10 миллионов
2) От 10 миллионов до миллиарда
3) Более миллиарда
"""

cc1, cc2, cc3 = {}, {}, {}
for cc, pop in cc_populations.items():
    if pop < 10000000:
        cc1[cc] = pop
    elif pop < 1000000000:
        cc2[cc] = pop
    else:
        cc3[cc] = pop
"""
RotateStyle принимает аргумент - цвет в ШЕСТНАДЦАТИРИЧНОМ ФОРМАТЕ RGB
Сначала пишется решется #
Затем шесть цифр
Первые две цифры - количество красного (Red)
Вторые две цифры - количество зеленого (Green)
Третьи две цифры - количество синего (Blue)
"""
style = RS(
    "#336699", base_style=LCS
)  #LCS - LightColorizedStyle из импорта - осветляет цфета оформления немного
wm = maps.World(style=style)
wm.title = "World population if 2010"
wm.add("0-10m", cc1)
wm.add("10m-1b", cc2)
wm.add("1b+", cc3)
wm.render_to_file("world_2010.svg")
		value=countries[51]
		print(value)
		code=get_country_code(country)
		if code:
			countries_list[code]=value

# Group the countries into 3 population levels.
cc_pops_1, cc_pops_2, cc_pops_3 = {},{},{}
for cc, pop in countries_list.items():
	if pop < 1:
		cc_pops_1[cc] = pop
	elif pop < 10:
		cc_pops_2[cc] = pop
	else:
		cc_pops_3[cc] = pop
		
# Styling world maps in pygal
wm_style =  RS('#108080',base_style=LCS)
wm= World(style=wm_style)

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

#wm=World()
wm.title='World GDP in 2016, by Country'
wm.add('0-10m', cc_pops_1)
wm.add('10m-1b', cc_pops_2)
wm.add('>1bn', cc_pops_3)

wm.render_to_file('world_gdp_2016.svg')
Beispiel #17
0
from pygal.maps.world import World
from pygal.style import LightColorizedStyle as LCS, RotateStyle as RS
from countries import get_country_code
filename = 'world_gdp_json.json'
filename_output = "world_gdp.svg"
with open(filename) as f:
	world_gdp_file = json.load(f)
#print 2010 population of each country
world_gdp = {} #a dictionary to hold country_code - gdp
for data_row in world_gdp_file:
	#print(data_row)
	if(data_row['Year'] == 2000):
		country_name = data_row['Country Name']
		#print(country_name)
		country_code = get_country_code(country_name)
		#country_code = data_row['Country Code'] #standardize country code for each country
		#print(country_code)
		gdp = int(float(data_row['Value'])) 		#we need to convert string into float first after that int() function can remove decimal
		#print(gdp)
		if country_code:
			world_gdp[country_code] = gdp
			#print(country_name + " " + country_code + " " + gdp)
print(world_gdp)
style_obj = RS('#FF0000', base_style = LCS) #return an object of style
wm = World(style = style_obj)
wm.title = 'World GDP 2000 by Country'
wm.add('2000', world_gdp)
wm.render_to_file("world_gdp_map.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/world_gdp_map.svg"})
import json
from pygal_maps_world.maps import World
from pygal.style import LightColorizedStyle as LCS,RotateStyle as RS
from country_codes import get_country_code
#将数据加载到一个列表中
file_name = "Document/population_data.json"
with open(file_name) as f:
    pop_date = json.load(f)
#打印每个国家2010年人口数量,创建一个包含人口数量的字典
cc_populations = {}
for pop_dict in pop_date:
    if pop_dict["Year"] == "2010":
        country_name = pop_dict["Country Name"]
        #Python不能直接将包含小数点的字符串'1127437398.85751' 转换为整数
        #为消除这种错误,我们先将字符串转换为浮点数,再将浮点数转换为整数
        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 = {}, {}, {}
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
Beispiel #19
0
from pygal.maps.world import World
from pygal.style import RotateStyle as RS, LightColorizedStyle as LS

filename = 'gdp_json.json'
with open(filename) as f:
    gdp = json.load(f)


def get_code(c_name):
    for c, name in COUNTRIES.items():
        if name == c_name:
            return c
    return None


gdp_country = {}
for c_dict in gdp:
    if c_dict['Year'] == 2016:
        c_name = c_dict['Country Name']
        c_gdp = int(float(c_dict['Value']))
        code = get_code(c_name)
        if code:
            gdp_country[code] = c_gdp

wm_style = RS('#663399', base_style=LS)
wm = World(style=wm_style)
wm.title = "World GDP by country - 2016"
wm.add('2016', gdp_country)
wm.render_to_file('images/w_gdp_2016.svg')

Beispiel #20
0
with open(filename) as f:
    pop_data = json.load(f)

#打印每个国家2010年的人口数量
cc_populations = {}  #创建包含人口数的字典
cc_pop_1, cc_pop_2, cc_pop_3 = {}, {}, {}  #按照人口规模进行分类的字典
for pop_dict in pop_data:
    if pop_dict['Year'] == '2010':
        country_name = pop_dict['Country Name']
        population = int(float(pop_dict['Value']))  #人口有小数的时候无法直接转化成int类型
        code = get_country_code(country_name)
        if code:
            cc_populations[code] = population
#按照人口分类
for cc, pop in cc_populations.items():
    if pop < 10000000:
        cc_pop_1[cc] = pop
    elif pop < 1000000000:
        cc_pop_2[cc] = pop
    else:
        cc_pop_3[cc] = pop

wm_style = RS(
    '#336699', base_style=LCS
)  #33,66,99分别为红绿蓝分量,最小是00,最大是FF 用的是十六进制表达RGB颜色,返回的是一个样式,LCS模块设置基色为加亮颜色
wm = pygal.maps.world.World(style=wm_style)
wm.title = 'World Population in 2010, by country'
wm.add('0-10m', cc_pop_1)
wm.add('10m-1bn', cc_pop_2)
wm.add('>1bn', cc_pop_3)
wm.render_to_file('world_population.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

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

# Check out Hex Color Chooser to customize the color
wm_style = RS('#41f476', 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')
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)
        # print(country_name + ": " + str(population))
        # if code:
        #     print(code + ": " + str(population))
        # else:
        #     print('ERROR - ' + country_name)
        if code:
            cc_pupulations[code] = population

cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for cc, pop in cc_pupulations.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('#FF2679', base_style=LCS)
wm = pygal_maps_world.maps.World(style=wm_style)
wm.title = 'World Population in 2010, by Country'
# wm.add('2010', cc_pupulations)
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_population.svg')
Beispiel #23
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
# 分成三组
cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for code, pop in cc_populations.items():
    if pop < 10000000:
        cc_pops_1[code] = pop
    elif pop < 1000000000:
        cc_pops_2[code] = pop
    else:
        cc_pops_3[code] = pop
wm_style = RS("#336699", base_style=LCS)
wm = pygal_maps_world.maps.World(style=wm_style)
wm.title = "World Population in 2010,by Country"
wm.add("<10m", cc_pops_1)
wm.add("10m-1b", cc_pops_2)
wm.add(">1b", cc_pops_3)

wm.render_to_file("world_population.svg")
                cnt_code = (pop_dict['Country Code']).lower()
                cc_population[cnt_code] = populat

# Группировка численности населения.
cc_pops_1, cc_pops_2, cc_pops_3 = {}, {}, {}
for cc, pop in cc_population.items():
    if pop < 10000000:
        cc_pops_1[cc] = pop
    elif pop < 1000000000:
        cc_pops_2[cc] = pop
    else:
        cc_pops_3[cc] = pop

# Численность населения страны за год.
fig = plt.figure(dpi=128, figsize=(10, 6))
plt.plot(years, population)
plt.title('Population of years ' + country)
fig.autofmt_xdate()
plt.xlabel('Years')
plt.ylabel('Population')
# plt.show()

# Мировая численность населения.
wm_style = RS('#336699')
wm = World()
wm.title = 'Word Population in 2016, 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('svg/word_population.svg')
Beispiel #25
0
# 打印每个国家2016年的GDP
for gdp_dict in gdp_data:
    if gdp_dict['Year'] == 2016:
        country_name = gdp_dict['Country Name']
        gdp = float(gdp_dict['Value'])
        code = get_country_code(country_name)
        if code:
            cc_gdps[code] = gdp

# 根据gdp值将所有的国家分成三组
cc_gdps_1, cc_gdps_2, cc_gdps_3 = {}, {}, {}
for cc, gdp in cc_gdps.items():
    if gdp < 10000000000:
        cc_gdps_1[cc] = gdp
    elif gdp < 100000000000:
        cc_gdps_2[cc] = gdp
    else:
        cc_gdps_3[cc] = gdp

# 看看每组分别包含多少个国家
# print(len(cc_gdps_1), len(cc_gdps_2), len(cc_gdps_3))

wm_style = RS('#d8886d', base_style=LCS)  # 让Pygal使用一种基色
wm = pmw.World(style=wm_style)
wm.title = 'World GDP in 2016, by Country'
wm.add('0-10bn', cc_gdps_1)
wm.add('10bn-100bn', cc_gdps_2)
wm.add('>100bn', cc_gdps_3)

wm.render_to_file('diagram/Grouped_World_GDP_2016.svg')
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

            print(len(cc_pops_1), len(cc_pops_2), len(cc_pops_3))

            wm_style = RS('#701212')
            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')


Beispiel #27
0
            cc_gdp_value[code] = gdp_value

# Группировка стран по уровню ВВП
cc_gdp_1, cc_gdp_2, cc_gdp_3, cc_gdp_4, cc_gdp_5 = {}, {}, {}, {}, {}
for cc, gdp in cc_gdp_value.items():
    if gdp < 100:
        cc_gdp_1[cc] = gdp
    if gdp < 500:
        cc_gdp_2[cc] = gdp
    if gdp < 1000:
        cc_gdp_3[cc] = gdp
    if gdp < 3000:
        cc_gdp_4[cc] = gdp
    else:
        cc_gdp_5[cc] = gdp

# Проверка количества стран на каждом уровне
print(len(cc_gdp_1), len(cc_gdp_2), len(cc_gdp_3), len(cc_gdp_4),
      len(cc_gdp_5))

wm_style = RS('#339966', base_style=LCS)
wm = pygal.maps.world.World(style=wm_style)
wm.title = 'ВВП стран на 2014 год, млрд.долл'
wm.add('< 100 млрд.долл', cc_gdp_1)
wm.add('100-500 млрд.долл', cc_gdp_2)
wm.add('500-1000 млрд.долл', cc_gdp_3)
wm.add('1-3 трлн.долл', cc_gdp_4)
wm.add('3< трлн.долл', cc_gdp_5)
wm.add('Нет данных', ['gf', 'ly', 'sy', 'er', 'kp', 'tw', 'gf', 'eh', 'aq'])
wm.render_to_file('world_gdp.svg')
Beispiel #28
0
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
response_dict = r.json()

repo_dicts = response_dict['items']

plot_dicts, names = [], []
for repo_dict in repo_dicts:
    plot_dict = {
        'value': repo_dict['stargazers_count'],
        'label': str(repo_dict['description']),
        'xlink': repo_dict['html_url']
    }

    plot_dicts.append(plot_dict)
    names.append(repo_dict['name'])

mystyle = RS('#333366', base_style=LGS)

myconfig = pygal.Config()
myconfig.x_label_rotation = 45
myconfig.show_legend = False
myconfig.truncate_label = 15
myconfig.show_y_guides = False
myconfig.width = 1300

chart = pygal.Bar(myconfig, style=mystyle)
chart.title = 'Python Projects'
chart.x_labels = names
chart.add('', plot_dicts)
chart.render_to_file('python_response.svg')
Beispiel #29
0
        population = int(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_2[cc] = pop
    elif pop < 10000000:
        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 = pygal.maps.world.World()
wm_style = RS('#336699', base_style=LCS)
wm = pygal.maps.world.World(style=wm_style)
wm.title = "World Population in 2010, by Country"
wm.add('0-10m', cc_pops_1)
wm.add('1-1bn', cc_pops_2)
wm.add('>1bn', cc_pops_3)

wm.render_to_file('light_style_world_population.svg')
Beispiel #30
0
filename = 'gdp_json.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 = gdp_dict['Value']
        code = get_country_code(country_name)
        if code:
            cc_gdp[code] = gdp
cc_gdp_1, cc_gdp_2, cc_gdp_3 = {}, {}, {}
for code, gdp in cc_gdp.items():
    if gdp < 10**10:
        cc_gdp_1[code] = gdp
    elif gdp < 10**12:
        cc_gdp_2[code] = gdp
    else:
        cc_gdp_3[code] = gdp
print(len(cc_gdp_1), len(cc_gdp_2), len(cc_gdp_3))
wm_style = RS('#e49898', base_style=LCS)
wm = pygal_maps_world.maps.World(style=wm_style)
wm.title = 'World GDP in 2016, by Country'
wm.add('0-10bn', cc_gdp_1)
wm.add('10bn-1tn', cc_gdp_2)
wm.add('>1tn', cc_gdp_3)

wm.render_to_file('world_gdp.svg')