Python draws a map of the world epidemic

Please click to download the world epidemic data": Epidemic Data Download
Note: This data is the result of March 12, 2022, in which the transparent area represents the number of confirmed cases is less than 100,000, and the white area represents no data for the country.

final effect:
insert image description here
Please add image description

Download the required python packages:

!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']

alldfregiongbmaxThe data:
insert image description here
mapping:

# 地图绘制
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()

Please add image description

Guess you like

Origin blog.csdn.net/wxfighting/article/details/123802999