时间:2022-06-10 08:27:21 | 栏目:Python代码 | 点击:次
世界疫情数据下载请点击》》:疫情数据下载
注:此数据是2022年3月12号的结果,其中透明的地方代表确诊人数小于10万人,白色的地方代表无该国家的数据。
最终效果:
下载需要的python包:
pip install echarts-countries-pypkg pip install echarts-china-provinces-pypkg pip install echarts-countries-china-cities-pypkg
import seaborn as sns import numpy as np import pandas as pd import matplotlib as mpl import matplotlib.pyplot as plt %matplotlib inline plt.rcParams['font.sans-serif']=['Microsoft YaHei'] # 用来正常显示中文标签 plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号 from datetime import datetime plt.figure(figsize=(16,10)) import pyecharts.options as opts from pyecharts.charts import Line from pyecharts.faker import Faker from pyecharts.charts import Bar import os from pyecharts.options.global_options import ThemeType
alldfgbcountrysum=pd.read_csv("alldfgbcountrysum.csv",encoding='utf-8-sig')
alldfregiongbmax=alldfgbcountrysum.groupby(alldfgbcountrysum['Country_Region'])['Confirmed','Recovered','Deaths','Date'].max()
alldfregiongbmax.reset_index(inplace=True)
alldfregiongbmax.loc[(alldfregiongbmax['Country_Region']=='US','Country_Region')]='United States' alldfregiongbmax[alldfregiongbmax['Countey_Region']=='United States']
alldfregiongbmax的数据:
地图绘制:
# 地图绘制 from pyecharts import options as opts from pyecharts.charts import Map import random regions=alldfregiongbmax['Country_Region'].to_list() regions2=[] for i in range(len(regions)): regions2.append(regions[i]) regions2 data=[(i,alldfregiongbmax[alldfregiongbmax['Country_Region']==i]['Confirmed'].to_list()) for i in regions2] data imap=( Map( init_opts=opts.InitOpts(bg_color='rgba(255,250,205,0.2)', width='1400px', height='1000px', page_title='疫情数据', theme=ThemeType.ROMA ) ) .add("确诊人数",data,"world",zoom=1) .set_global_opts( title_opts=opts.TitleOpts(title="世界疫情数据--地图绘制"), legend_opts=opts.LegendOpts(is_show=True), visualmap_opts=opts.VisualMapOpts(max_=80000000,min_=100000,is_piecewise=True,split_number=10), ) # 通过更改max_ ,min_ 来调整地图的颜色![请添加图片描述](https://img-blog.csdnimg.cn/58280443a30949cdbae0f4c35d223ed5.gif) ) imap.render_notebook()