基于Python绘制世界疫情地图详解
作者:渴望成为寂寞胜者 时间:2021-11-23 09:10:36
世界疫情数据下载请点击》》:疫情数据下载
注:此数据是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()
来源:https://blog.csdn.net/wxfighting/article/details/123802999
标签:Python,疫情,地图
0
投稿
猜你喜欢
Pytorch转onnx、torchscript方式
2022-05-03 11:10:43
用python实现爬取奥特曼图片实例
2022-09-23 00:25:18
Dreamweaver4探谜系列(2)
2010-05-13 12:08:00
使用ODBC接口访问MySQL
2009-02-13 13:59:00
pytorch 求网络模型参数实例
2021-12-08 08:41:11
Python实现模拟时钟代码推荐
2023-08-03 05:26:09
Python语法详解之decorator装饰器
2021-07-15 23:11:45
python paramiko利用sftp上传目录到远程的实例
2023-08-10 02:53:23
sklearn线性逻辑回归和非线性逻辑回归的实现
2021-06-16 04:04:31
利用python爬取散文网的文章实例教程
2023-06-17 10:40:18
python查看自己安装的所有库并导出的命令
2022-03-01 03:03:08
Python numpy实现二维数组和一维数组拼接的方法
2022-02-24 09:40:53
ASP实现GB2312转UTF-8函数
2009-02-26 13:08:00
css基础教程属性篇之盒子模型
2008-07-29 12:05:00
Python实现输入二叉树的先序和中序遍历,再输出后序遍历操作示例
2023-04-20 15:10:44
Linux 发邮件磁盘空间监控(python)
2022-03-15 09:17:24
详解Python requests模块
2021-12-31 21:55:12
Python 爬虫之超链接 url中含有中文出错及解决办法
2023-07-27 00:25:06
浅谈python中np.array的shape( ,)与( ,1)的区别
2022-12-07 21:22:09
Python正则表达式和元字符详解
2021-02-26 02:54:19