Python crawler epidemic visualization

After learning pyecharts, I tried a little trick to make a visualization of the Chinese epidemic situation.

First install the pyecharts library

1. Can be installed directly on pycharm

2. It can also be installed faster by command line, win+r cmd

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pyecharts 

Libraries to use today

from pyecharts import options as opts
from pyecharts.charts import Map

 

For the data, we can directly use the data of today’s epidemic situation in our previous article. If you want to learn the previous code, please refer to

Python crawler epidemic today_Lorrey_'s Blog-CSDN Blog 

Use the last code directly here, don’t need all

import requests
import json

url='https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail,diseaseh5Shelf'
r=requests.post(url)
retext=r.text

data=json.loads(retext)

citylist=data['data']['diseaseh5Shelf']['areaTree'][0]['children']

alist=[]
for i in citylist:
    #print(i['name'],i['total']['nowConfirm'],i['total']['wzz'])
    alist.append([i['name'],i['total']['nowConfirm']+i['total']['wzz']])
print(alist)

 

Next is pyecharts visualization

Map(init_opts=opts.InitOpts(width="1500px", height="900px", page_title='China Epidemic Map'))
    .add(
    'number of people infected',
    alist,
    maptype='china',
    is_roam=True,
    is_selected=True,
    is_map_symbol_show=True # Whether to mark graphics
)
title_opts=opts.TitleOpts(title="Come on China",
                          title_target="blank", # new window opens
                          subtitle="China Epidemic Map", # Subtitle
                          subtitle_target="self"), # The current window is open
visualmap_opts=opts.VisualMapOpts(is_show=True,
                                  max_=300000,
                                  is_calculable=True,
                                  is_piecewise=True,
                                  pieces=[
                                            {"min":10000},
                                            {"min":5000,"max":5000},
                                            {"min": 1000, "max": 5000},
                                            {"min": 500, "max": 1000},
                                            {"min": 10, "max": 500},
                                            {"max": 10}
                                        ],
                                  range_text=["High", "Low"],
                                  border_color="#000")

The complete code is as follows:

from pyecharts import options as opts
from pyecharts.charts import Map
from pyecharts.faker import Faker
import requests
import json
from openpyxl import Workbook
from openpyxl import load_workbook

url='https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=statisGradeCityDetail,diseaseh5Shelf'
r=requests.post(url)
retext=r.text

data=json.loads(retext)

citylist=data['data']['diseaseh5Shelf']['areaTree'][0]['children']

alist=[]
for i in citylist:
    #print(i['name'],i['total']['nowConfirm'],i['total']['wzz'])
    alist.append([i['name'],i['total']['nowConfirm']+i['total']['wzz']])
print(alist)

#pyecharts 可视化

provience_yiqing = (
    Map(init_opts=opts.InitOpts(width="1500px", height="900px", page_title='中国疫情地图'))
        .add(
        '感染人数',
        alist,
        maptype='china',
        is_roam=True,
        is_selected=True,
        is_map_symbol_show=True  # 是否标记图形
    )


        .set_global_opts(
        title_opts=opts.TitleOpts(title="中国加油",
                                  title_target="blank",  # 新窗口打开
                                  subtitle="中国疫情地图",  # 副标题
                                  subtitle_target="self"),  # 当前窗口打开

        visualmap_opts=opts.VisualMapOpts(is_show=True,
                                          max_=300000,
                                          is_calculable=True,
                                          is_piecewise=True,
                                          pieces=[
                                                    {"min":10000},
                                                    {"min":5000,"max":5000},
                                                    {"min": 1000, "max": 5000},
                                                    {"min": 500, "max": 1000},
                                                    {"min": 10, "max": 500},
                                                    {"max": 10}
                                                ],
                                          range_text=["High", "Low"],
                                          border_color="#000")

        )
        .set_series_opts(
        label_opts=opts.LabelOpts(is_show=True)
    )
        .render('中国疫情.html')

)

Open the html file, very beautiful visualization

 

Guess you like

Origin blog.csdn.net/Lorrey_/article/details/124435328