世界疫情数据下载请点击》》:疫情数据下载
注:此数据是2022年3月12号的结果,其中透明的地方代表确诊人数小于10万人,白色的地方代表无该国家的数据。
最终效果:
下载需要的python包:
1
2
3
|
pip install echarts-countries-pypkg pip install echarts-china-provinces-pypkg pip install echarts-countries-china-cities-pypkg |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
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 |
1
|
alldfgbcountrysum = pd.read_csv( "alldfgbcountrysum.csv" ,encoding = 'utf-8-sig' ) |
1
|
alldfregiongbmax = alldfgbcountrysum.groupby(alldfgbcountrysum[ 'Country_Region' ])[ 'Confirmed' , 'Recovered' , 'Deaths' , 'Date' ]. max () |
1
|
alldfregiongbmax.reset_index(inplace = True ) |
1
2
|
alldfregiongbmax.loc[(alldfregiongbmax[ 'Country_Region' ] = = 'US' , 'Country_Region' )] = 'United States' alldfregiongbmax[alldfregiongbmax[ 'Countey_Region' ] = = 'United States' ] |
alldfregiongbmax的数据:
地图绘制:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# 地图绘制 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地图内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!
原文链接:https://blog.csdn.net/wxfighting/article/details/123802999