基于Python繪制世界疫情地圖詳解
更新時間:2022年03月29日 08:56:41 作者:渴望成為寂寞勝者
這篇文章主要介紹了如何使用Python繪制世界疫情地圖,本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
世界疫情數(shù)據(jù)下載請點擊》》:疫情數(shù)據(jù)下載
注:此數(shù)據(jù)是2022年3月12號的結果,其中透明的地方代表確診人數(shù)小于10萬人,白色的地方代表無該國家的數(shù)據(jù)。
最終效果:
下載需要的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的數(shù)據(jù):
地圖繪制:
# 地圖繪制 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='疫情數(shù)據(jù)', theme=ThemeType.ROMA ) ) .add("確診人數(shù)",data,"world",zoom=1) .set_global_opts( title_opts=opts.TitleOpts(title="世界疫情數(shù)據(jù)--地圖繪制"), legend_opts=opts.LegendOpts(is_show=True), visualmap_opts=opts.VisualMapOpts(max_=80000000,min_=100000,is_piecewise=True,split_number=10), ) # 通過更改max_ ,min_ 來調整地圖的顏色 ) imap.render_notebook()
到此這篇關于基于Python繪制世界疫情地圖詳解的文章就介紹到這了,更多相關Python地圖內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Python實現(xiàn)加解密,編碼解碼和進制轉換(最全版)
這篇文章主要為大家詳細介紹了Python實現(xiàn)加解密、編碼解碼、進制轉換、字符串轉換的最全版操作方法,文中的示例代碼講解詳細,大家可以收藏一下2023-01-01在Django中創(chuàng)建動態(tài)視圖的教程
這篇文章主要介紹了在Django中創(chuàng)建動態(tài)視圖的教程,Django是Python重多人氣框架中最為著名的一個,需要的朋友可以參考下2015-07-07