基于Python绘制世界疫情地图详解

这篇文章主要介绍了如何使用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() 

到此这篇关于基于Python绘制世界疫情地图详解的文章就介绍到这了,更多相关Python地图内容请搜索0133技术站以前的文章或继续浏览下面的相关文章希望大家以后多多支持0133技术站!

以上就是基于Python绘制世界疫情地图详解的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python