【无标题】

#导入所需的库import requestsimport jsonimport matplotlib.pyplot as pltimport numpy as npimport tkinter as tkdef fin(name): global response, data, china_data, i, j hd = {‘User-Agent’: ‘Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0’} response = requests.get(‘http//view.inews.qq.com/g2/getOnsInfo?name=disease_h5’, timeout=10, headers=hd).json() data = json.loads(response[‘data’]) china_data = data[‘areaTree’][0][‘children’] china_set = []#设置一个列表 for i in china_data: i.pop(‘today’)#移出列表 i.pop(‘total’) for j in i[‘children’]: j.pop(‘today’) j[‘total’].pop(‘confirm’) j[‘total’].pop(‘deadRate’) j[‘total’].pop(‘healRate’) for i in china_data:#遍历中国疫情数据 for j in i[‘children’]:#遍历个城市数据 if name == j[‘name’]: return j[‘total’] return Falsedef inputcity(urb1): city = urb1 data=fin(city) return city,data#比较两个城市的疫情数据def compare(urb1,urb2): city1, data1 = inputcity(urb1) city2, data2 = inputcity(urb2) # 这两行代码解决 plt 中文显示的问题 plt.rcParams[‘font.sans-serif’] = [‘SimHei’] plt.rcParams[‘axes.unicode_minus’] = False # 输入统计数据 xlable = (‘确诊人数’, ‘死亡人数’, ‘治愈人数’) allPeople1 = list(data1.values()) allPeople2 = list(data2.values()) bar_width = 0.5 # 设置条形宽度 index_urb1 = np.arange(len(xlable)) # 设置第一个城市条形图的横坐标 index_urb1 = index_urb1 + bar_width # 设置第一个城市条形图的横坐标 #bar函数画出条形图 plt.bar(index_urb1, height=allPeople1, width=bar_width, color=‘r’, label=urb1) plt.bar(index_urb2, height=allPeople2, width=bar_width, color=‘b’, label=urb2) plt.legend() # 显示统计图 plt.xticks(index_urb1 + bar_width / 2, xlable) # 设置横坐标轴刻度位置 plt.ylabel(‘人数’) # 纵坐标轴标题 plt.title(’’) # 图形标题 plt.show()window = tk.Tk() #设置初始窗口大小window.title(" ")#窗口标题设置window.geometry(“300x300+800+800”)#窗口参数设置t1.pack()t2 = tk.Entry(window,show = None)t2.pack()def insert_point(): urb1 = t1.get() urb2 = t2.get() compare(urb1,urb2)b1 =tk.Button(window,text=“point”,width = 10,height = 3,command = insert_point)#图形参数设置b1.pack()window.mainloop()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值