#coding=utf-8
import json
import pygal.maps.world
#Pygal样式保存在模块style中,包括RotateStyle调整颜色和LightColorizedStyle加亮颜色
#也可以写成from pygal.style import LightColorizedStyle, RotateStyle
import pygal.style
from country_codes import get_country_code
#将数据加载到列表中
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'][:4]=='2010':
country_name=pop_dict['Country Name']
poplulation=int(pop_dict['Value'])
code=get_country_code(country_name)
if code:
cc_populations[code]=poplulation
#根据人口数量分组
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是一个样式对象,第一个实参表示颜色,十六进制格式,分别表示红绿蓝的分量(RGB),第二个实参表示加亮颜色主题
wm_style=pygal.style.RotateStyle('#3399AA',base_style=pygal.style.LightColorizedStyle)
wm=pygal.maps.world.World(style=wm_style)
wm.title="World Population in 2010,by Country"
#add接收一个标签和一个列表,此例中标签为人口数量区间,列表是国家和人口数量的列表
wm.add('0-10m',cc_pops_1)
wm.add('10m-1bn',cc_pops_2)
wm.add('>1bn',cc_pops_3)
wm.render_to_file('world_population.svg')
from pygal.maps.world import COUNTRIES
from pygal_maps_world.i18n import COUNTRIE
wm=pygal.maps.world.World()
wm_style=pygal.style.LightColorizedStyle
wm_style=pygal.style.RotateStyle('#3399AA',base_style=pygal.style.LightColorizedStyle)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有