世界疫情數據下載:
方法一:關注微信公眾號大數據智庫(公眾號二維碼在我的主頁左下角),回復疫情數據,即可獲取網盤鏈接
方法二:在gitee上面下載》》點擊:疫情數據下載
注:此數據是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)
# 這句話的意思是把數據當中國家名US改成United States,否則地圖上無法顯示美國數據
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),
)
)
# imap.render_notebook() # 這句話的意思是在我運行的環(huán)境juypter notebook直接呈現地圖,不同的軟件不一樣
imap.render("map.html") # 這句話的意思是在本地的文件夾下生成一個HTML文件,聯網的狀態(tài)下查看
于2022-03-30更新如下:
注:如果代碼運行不了,可以私信我,我看看是哪里有問題。
- 我選擇的代碼運行工具是
juypter notebook
- 世界疫情數據下載請點擊》》:疫情數據下載
- 要把我最上面的疫情數據下載的Excel文件下載下來。
- 把下載下來的這個
alldfgbcountrysum.csv
放在相應的位置(設置好路徑) - 選擇
imap.render("map.html")
,則要在聯網的狀態(tài)下顯示 - 我上面代碼的最后又補了一些注釋供大家參考
然后在相同的路徑下新建文件:
看看自己運行后得到的alldfregiongbmax
是不是下面的結果:
如下圖:
于2022-04-17更新如下:文章來源:http://www.zghlxwxcb.cn/news/detail-426442.html
有小伙伴說數據下載出來無法得到Excel文件, 得到的是下面的結果:
解決方法:
直接全選復制,粘貼到txt,然后改個后綴名,就能成功運行了。文章來源地址http://www.zghlxwxcb.cn/news/detail-426442.html
到了這里,關于Python繪制世界疫情地圖的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!