python新冠状疫情数据可视化-省趋势图

python新冠状疫情数据可视化-省趋势图

更新:有小伙伴反应数据集过期,我附个百度网盘链接链接:https://pan.baidu.com/s/1X0yd_ecoaxCl2CTrM57pqA
提取码:60rw

数据来自GITHUB数据仓库(每小时刷新):https://github.com/BlankerL/DXY-COVID-19-Data
我用的是json文件下的DXYArea-TimeSeries.json文件,话不多说(我只是一个为完成作业的小菜鸟)

这是效果图

python新冠状疫情数据可视化-省趋势图_第1张图片
下面是代码

import json
import urllib.request
import pandas as pd
from pyecharts import options as opts
from pyecharts.charts import Line, Map

# 想要取哪个城市,只需更改省名称即可
province_name = '山东'
cities = []
def flatten__data():
    total_file = open("DXYArea-TimeSeries.json", encoding='utf-8')
    total_json = json.load(total_file)
    # print(type(total_json))
    for i in total_json:
        if i['provinceShortName'] == province_name:
            province_url = i['statisticsData']
            break
    request = urllib.request.Request(province_url)
    response = urllib.request.urlopen(request)
    unicodester = json.load(response)
    # print(unicodester)
    # day_data =[]
    for day_data in unicodester['data']:
        daily_data = {
            '日期':day_data['dateId'],
            '累计确诊':day_data['confirmedCount'],
            '累计死亡':day_data['deadCount'],
            '累计治愈':day_data['curedCount'],
            '疑似':day_data['suspectedCount'],
            '现有确诊':day_data['confirmedCount']-day_data['deadCount']-day_data['curedCount']
        }
        # day_data.append(daily_data)
        cities.append(daily_data)
    # print(cities)
    return cities
def draw_line():
    data = flatten__data()
    chinaDayAddList = pd.DataFrame(data)[
        ['日期','现有确诊','累计确诊','累计死亡','累计治愈']]
    # print(chinaDayAddList)
    chinaDayAddList['日期'] = chinaDayAddList['日期'].map(str)
    chinaDayAddList.head()
    total_line = (
        Line()
            # x轴
            .add_xaxis(list(chinaDayAddList['日期']))
            # y轴
            .add_yaxis('现有确诊', list(chinaDayAddList['现有确诊']),label_opts=opts.LabelOpts(is_show=False))
            .add_yaxis('累计确诊', list(chinaDayAddList['累计确诊']),label_opts=opts.LabelOpts(is_show=False))
            .add_yaxis('累计治愈', list(chinaDayAddList['累计治愈']),label_opts=opts.LabelOpts(is_show=False))
            .add_yaxis('累计死亡', list(chinaDayAddList['累计死亡']),label_opts=opts.LabelOpts(is_show=False))
            # 标题
            .set_global_opts(title_opts=opts.TitleOpts(title=province_name+"现有确诊、累计确诊、累计\n治愈、累计死亡人数关于时间变化趋势"))

    )
    # 折线图保存进html文件中
    total_line.render(province_name+'疫情趋势.html')

if __name__ == "__main__":
    # my_data()
    draw_line()
    # draw_map()


看到结尾了,点个赞再走吧~

你可能感兴趣的:(python)