Ai
1 Star 0 Fork 0

leetone/my_python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
world_population.py 781 Bytes
一键复制 编辑 原始数据 按行查看 历史
leetone 提交于 2018-08-15 15:56 +08:00 . 利用pygal绘制世界人口地图
import json
import pygal.maps.world
from country_code import get_country_code
#将数据加载到一个列表中
filename = 'population.json'
with open(filename) as f:
pop_data = json.load(f)
#创建一个包含人口数量的字典
cc_populations = {}
#打印每个国家2018年的预估人口
for pop_dict in pop_data:
if pop_dict["Year"] == 2015:
country = pop_dict["Country Name"]
population = pop_dict["Value"]
code = get_country_code(country)
if code:
cc_populations[code] = population
print(country+": "+str(population))
print(cc_populations)
#开始绘制世界地图
wm = pygal.maps.world.World()
wm.title = "The World Map Population Of 2016"
wm.add('2016',cc_populations)
wm.render_to_file("world_map.svg")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/leetone123/my_python.git
git@gitee.com:leetone123/my_python.git
leetone123
my_python
my_python
master

搜索帮助