【Python】疫情卷土重来?Python可视化带你追踪疫情的最新动态
机器学习初学者
共 2914字,需浏览 6分钟
·
2021-11-04 19:43
Python
可视化来追踪一下当下疫情的最新动态,也希望大家在外能够注意安全,戴好口罩最新的动态
category_list = ["黑龙江-黑河", "河北-石家庄", "甘肃-兰州", "甘肃-天水", "内蒙古-阿拉善盟", "宁夏-银川", "河北-保定", "黑龙江-哈尔滨", "江西-九江",
"山东-日照", "浙江-杭州", "青海-西宁", "内蒙古-锡林郭勒"]
num_list1 = [79, 8, 68, 15, 143, 21, 2, 3, 1, 10, 1, 4, 16]
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.SHINE))
.add_xaxis(category_list)
.add_yaxis("不同省份", num_list1)
.set_global_opts(title_opts=opts.TitleOpts(title="近期31省市的本土病例"),
xaxis_opts=opts.AxisOpts(axislabel_opts = opts.LabelOpts(rotate=30)))
)
bar.render("yiqing_location.html")
output
provinces = ["黑龙江", "甘肃", "上海", "浙江", "河北", "内蒙古", "台湾", "云南", "山东",
"福建", "四川", "宁夏", "香港", "江西", "重庆", "广西", "青海", "湖北", "广东",
"江苏", "河南", "湖南", "北京", "安徽", "新疆", "陕西", "吉林", "天津", "辽宁", "山西",
"海南", "贵州", "澳门", "西藏"]
num = [84, 105, 62, 52, 13, 172, 1823, 83, 35, 22, 13, 33, 99, 2, 1, 35,
5, 12, 32, 3, 22, 7, 38, 0, 0, 21, 3, 13, 7, 0, 0, 11, 4, 0]
c = (
Map(init_opts=opts.InitOpts(theme=ThemeType.SHINE))
.add("不同省份", [list(z) for z in zip(provinces, num)], "china")
.set_global_opts(
title_opts=opts.TitleOpts(title="不同省份的疫情确诊情况"),
visualmap_opts=opts.VisualMapOpts(max_=180, is_piecewise=True),
)
.render("map_visualmap_piecewise.html")
)
output
Pyecharts
当中的Tab
组件将上面绘制的两张图组合成可视化大屏,需要注意的是,需要将上面的代码整合成函数def generate_bar():
category_list = ["各个省份城市"]
num_list1 = ["对应的数据"]
bar = (
Bar(init_opts=opts.InitOpts(theme=ThemeType.SHINE))
.add_xaxis(category_list)
.add_yaxis("不同省份", num_list1)
.set_global_opts(title_opts=opts.TitleOpts(title="近期31省市的本土病例"),
xaxis_opts=opts.AxisOpts(axislabel_opts = opts.LabelOpts(rotate=30)))
)
return bar
def generate_map():
provinces = ["各个省份....."]
num = ["各个省份对应的数据"]
map = (
Map(init_opts=opts.InitOpts(theme=ThemeType.SHINE))
.add("不同省份", [list(z) for z in zip(provinces, num)], "china")
.set_global_opts(
title_opts=opts.TitleOpts(title="不同省份的疫情确诊情况"),
visualmap_opts=opts.VisualMapOpts(max_=180, is_piecewise=True),
)
)
return map
tab = Tab()
tab.add(generate_bar(), "不同省市的确诊病例")
tab.add(generate_map(), "全国不同省份的确诊病例")
tab.render("test.html")
output
预防须知
保持个人卫生,打喷嚏或者咳嗽时应用纸巾掩盖口鼻,把用过的纸巾弃置于有盖垃圾箱内,然后彻底清洁双手
减少前往人流密集的场所。如不可避免,应佩戴外科口罩
如有身体不适,特别是有发烧或者咳嗽,应佩戴上外科口罩,并尽快就诊
往期精彩回顾 本站qq群554839127,加入微信群请扫码:
评论