Matplotlib use map drawn epidemic (Shaanxi)

Knowledge used in the project: 
. 1, ZIP (): ZIP () is a built-in Python function that takes a series of iterations the object as a parameter, the corresponding element of the object packed into one tuple (a tuple ), 0-th tuple corresponding to all the 0th element parameters, the first tuple corresponding to all elements of a parameter, and so on, and then returns list (list) from these tuples thereof. If the length parameter passed ranging from the same list of parameters and the length of the shortest object is returned. zip ([1,2,3,4], [5,6,7,8 ]) returns [(1, 5), (2, 6), (3, 7), (4, 8)] 
2 , # json.loads () is used to read a character string, converts the data into a dictionary format python 

# - * - Coding: UTF-. 8 - * - 
Import Time, JSON, Requests 
Import matplotlib.pyplot aS PLT 
Import numpy NP AS 

# Tencent epidemic gripping real-time data json 
url = 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=&_=%d'% int (time.time () * 1000) 
origindatas requests.get = (URL = URL) 
Print ( "origindata:" + origindatas.json () [ 'data']) # fetch the data into a format and json obtain inside data 
print ( "status code:" + str (origindatas.
= json.loads Data (requests.get (URL = URL) .json () [ 'Data'])  
Print ( "DATAS:") 
Print (str (the Data)) 
Print (data.keys ()) 

# State statistics information (34 provinces of Hubei, Henan and Zhejiang Hunan, Guangdong, Anhui ....) 
c_datas the Data = [ 'areaTree'] [ 0] [ 'Children'] 
Print (len (c_datas)) 
for Item in c_datas: 
    Print (Item [ 'name'], End = "") # get the name of each province province of 
the else: 
    Print ( "\ the n-") 

# display data Shaanxi 
TECHNOLOGY = c_datas [. 17] [ 'Children'] 
for data in TECHNOLOGY: 
    Print (data) 
# parse json data 
total_datas = {} 
shanxi_datas = {} 
for data in c_datas: 
    IF data [ 'name'] in total_datas Not: 
        total_datas.update ({data [ 'name']: 0}) 
    for province_data in data [ 'Children']: # acknowledged data acquired in each province
        total_datas [the Data [ 'name']] + = int (province_data [ 'Total'] [ 'Confirm The']) 
Print (total_datas) 
# Shaanxi Province to obtain data for each city 
for SX in shanxi: 
    Print (SX [ 'name'] + "\ n-") 
    Print (int (SX [ 'Total'] [ 'Confirm'])) 
    shanxi_datas [SX [ 'name']] = int (SX [ 'Total'] [ 'Confirm'] ) 
Print (shanxi_datas) 

names shanxi_datas.keys = () 
the nums = shanxi_datas.values () 

# draw bar 
plt.figure (figsize = [10,. 6]) 
plt.bar (names, the nums, width = 0.3, Color = 'Green') 
# set the title 
plt.xlabel ( "region", fontproperties = 'SimHei', rotation = 90, size = 12)  
PLT.ylabel ( "number", fontproperties = 'SimHei', size = 12)
plt.title ( "Shaanxi Province cities epidemic data comparison", fontproperties = 'SimHei',size=20)
plt.xticks(list(names), fontproperties='SimHei', rotation=-45, size=10)
# Data is displayed on each graphic 
for A, B in ZIP (List (names), List (the nums)): 
    plt.text (A, B, B, HA = 'Center', VA = 'bottom',. 6 size = ) 
plt.show ()

 

Published 14 original articles · won praise 1 · views 277

Guess you like

Origin blog.csdn.net/weixin_38829588/article/details/104505897