# https://github.com/CSSEGISandData/COVID-19
from typing import List
import pandas as pd
import numpy as np
import pyecharts.options as opts
from pyecharts.globals import ThemeType
from pyecharts.commons.utils import JsCode
from pyecharts.charts import Timeline, Grid, Bar, Map, Pie, Line, Page
confirmed = pd.read_csv("./time_series_covid19_confirmed_global.csv")
death = pd.read_csv("time_series_covid19_deaths_global.csv")
recovered = pd.read_csv("time_series_covid19_recovered_global.csv")
china_confirmed = confirmed[confirmed["Country/Region"] == "China"]
china_death = death[death["Country/Region"] == "China"]
china_recovered = recovered[recovered["Country/Region"] == "China"]
columns = {d: d[:-3] for d in china_confirmed.columns[4:]} # 把末尾三位年份去掉,如'3/10/20': '3/10'
china_confirmed = china_confirmed.rename(columns=columns)
china_death = china_death.rename(columns=columns)
china_recovered = china_recovered.rename(columns=columns) # 这个的index跟上面两个不一样,要做减法时要index和column对应
china_recovered.index = range(49, 82)
provinces = ['安徽', '北京', '重庆', '福建', '甘肃', '广东', '广西', '贵州', '海南', '河北', '黑龙江', '河南', '香港',
'湖北', '湖南', '内蒙古', '江苏', '江西', '吉林', '辽宁', '澳门', '宁夏', '青海', '陕西', '山东', '上海',
'山西', '四川', '天津', '西藏', '新疆', '云南', '浙江']
time_list = china_confirmed.columns[4:].to_list()
max_all = [67803, 3213, 64142, 67803]
# 全国累计
total_num_all = [[sum(china_confirmed[t]) for t in time_list],
[sum(china_death[t]) for t in time_list],
[sum(china_recovered[t]) for t in time_list]]
# 剩余确诊
now = np.array(total_num_all[0]) - np.array(total_num_all[1]) - np.array(total_num_all[2])
now = now.tolist()
total_num_all.append(now)
titles = ["全国新冠肺炎确诊情况", "全国新冠肺炎死亡情况", "全国新冠肺炎治愈情况", "全国新冠肺炎现存确诊情况"]
line_titles = ["全国新冠肺炎累计确诊人数", "全国新冠肺炎累计死亡人数", "全国新冠肺炎累计治愈人数", "全国新冠肺炎现存确诊人数"]
china_now = china_confirmed[china_confirmed.columns[4:]] - china_death[china_death.columns[4:]] - china_recovered[china_recovered.columns[4:]]
data_all = [china_confirmed, china_death, china_recovered, china_now]
pieces_all = [[{"value": 0, "color": "#FFFFFF"},
{"min": 1, "max": 99, "label": "1-99", "color": "#FFEBCD"},
{"min": 100, "max": 499, "label": "100-499", "color": "#FF8C00"},
{"min": 500, "max": 999, "label": "500-999", "color": "#EE2C2C"},
{"min": 1000, "max": 19999, "label": "1000-19999", "color": "#CD2626"},
{"min": 20000, "label": ">=20000", "color": "#8B1A1A"}],
[{"value": 0, "color": "#FFFFFF"},
{"min": 1, "max": 9, "label": "1-9", "color": "#FFEBCD"},
{"min": 10, "max": 49, "label": "10-49", "color": "#FF8C00"},
{"min": 50, "max": 199, "label": "50-199", "color": "#EE2C2C"},
{"min": 200, "max": 999, "label": "200-999", "color": "#CD2626"},
{"min": 1000, "label": ">=1000", "color": "#8B1A1A"}],
[{"min": 0, "max": 99, "label": "0-99", "color": "#FFFFE0"},
{"min": 100, "max": 499, "label": "100-499", "color": "#98FB98"},
{"min": 500, "max": 999, "label": "500-999", "color": "#3CB371"},
{"min": 1000, "max": 19999, "label": "1000-19999", "color": "#2E8B57"},
{"min": 20000, "label": ">=20000", "color": "#006400"}]
]
pieces_all.append(pieces_all[0])
def get_line(date: str):
data_mark_all = [[], [], [], []]
for j in range(4):
i = 0
for x in time_list:
if x == date:
data_mark_all[j].append(total_num_all[j][i])
else:
data_mark_all[j].append("")
i = i + 1
line_chart = (
Line(init_opts=opts.InitOpts(theme=ThemeType.DARK))
.add_xaxis(time_list)
.add_yaxis("累计确诊", total_num_all[0], is_smooth=True)
.add_yaxis(
"累计确诊",
data_mark_all[0],
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
)
.add_yaxis("累计死亡", total_num_all[1], is_smooth=True)
.add_yaxis(
"累计死亡",
data_mark_all[1],
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
)
.add_yaxis("累计治愈", total_num_all[2], is_smooth=True)
.add_yaxis(
"累计治愈",
data_mark_all[2],
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
)
.add_yaxis("现存确诊", total_num_all[3], is_smooth=True)
.add_yaxis(
"现存确诊",
data_mark_all[3],
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
)
.set_series_opts(label_opts=opts.LabelOpts(is_show=False))
)
return line_chart
def get_date_chart(which: int, date: str):
if which == 4:
return get_line(date)
data = data_all[which]
map_data = [list(z) for z in zip(provinces, data[date])]
map_chart = (
Map()
.add(
series_name="",
data_pair=map_data,
zoom=1,
center=[119.5, 34.5],
is_map_symbol_show=False,
itemstyle_opts={
"normal": {"areaColor": "#323c48", "borderColor": "#404a59"},
"emphasis": {
"label": {"show": Timeline},
"areaColor": "rgba(255,255,255, 0.5)",
},
},
)
.set_global_opts(
title_opts=opts.TitleOpts(
title="" + date[0] + "月" + date[2:] + "日" + titles[which],
subtitle="",
pos_left="center",
pos_top="top",
title_textstyle_opts=opts.TextStyleOpts(
font_size=25, color="rgba(255,255,255, 0.9)"
),
),
tooltip_opts=opts.TooltipOpts(
formatter='{b}: {c}'
),
visualmap_opts=opts.VisualMapOpts(
is_calculable=True,
dimension=0,
pos_left="30",
pos_top="center",
pieces=pieces_all[which],
is_piecewise=True,
textstyle_opts=opts.TextStyleOpts(color="#ddd"),
),
)
)
data_mark: List = []
i = 0
for x in time_list:
if x == date:
data_mark.append(total_num_all[which][i])
else:
data_mark.append("")
i = i + 1
line_chart = (
Line()
.add_xaxis(time_list)
.add_yaxis("", total_num_all[which], is_smooth=True)
.add_yaxis(
"",
data_mark,
markpoint_opts=opts.MarkPointOpts(data=[opts.MarkPointItem(type_="max")]),
)
.set_series_opts(
label_opts=opts.LabelOpts(is_show=False),
# value的值应该只有人数才对,不知道为什么这里value的值是日期加逗号加人数,就像是2/26,45365,第五张纯折线图都没有这个问题,所以只能jscode了
tooltip_opts=opts.TooltipOpts(
formatter=JsCode(
"""function(params) {
return String(params.value).replace(',', ': ')
}"""
),
),
)
.set_global_opts(
title_opts=opt
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
使用pyecharts,对疫情进行可视化,包含确诊,死亡,治愈,折线四张大图。前三张大图样式类似,一张大图包含map,bar,line,pie四合一,有热力标签,带时间控制条,会随着日期变化,可查看任意一天数据,样式美观。压缩包中包含py代码,生成的可视化html文件及疫情数据,数据截止到4月8号,如有需要可从代码所给网站中自行下载数据再扩充
资源推荐
资源详情
资源评论


























收起资源包目录






共 5 条
- 1
资源评论

- weixin_397397892021-12-10跑不通啊啊
- 小凡爱学习2020-07-16博主,请问有相关的制作教程吗及勒2020-09-23额我是看pyecharts官网的一个示例加以改写做的,这种也只能看看官网示例看看api怎么用,教程很难找

及勒
- 粉丝: 4
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 项目月度计划成本编制办法.doc
- 【精华】教师个人工作总结范文合集五篇.doc
- 基于社会网络分析的广播类融媒体信息传播研究.docx
- 中心医院门诊科技楼工程.doc
- 分联盟雅思阅读系统班填空题PPT.pptx
- 浅议如何激发职业院校学生学习《计算机应用基础》课程的兴趣.docx
- 价值100万的咨询方案:企业大学建设方案.doc
- 选择空调的技巧.doc
- 管理会计课件讲义.doc
- 工程招标文件模版.doc
- 基于PLC控制的自动售货机方案设计书74100.doc
- 办公室里十个成长机会.ppt
- 职务分析样本——工业工厂类》.docx
- 福建某厂房及配套工程塑钢门窗安装施工技术交底.doc
- 深度揭秘:如何实现 DeepSeek-R1 的开源复现之旅 首个 DeepSeek-R1 开源复现成果发布,Open-R1 正式亮相 一文读懂:DeepSeek-R1 开源复现项目的完整攻略 Open
- 基于初步危害分析的城市轨道交通系统安全性分析.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
