forked from FelixZFB/wuhan_2019-nCoV
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
220 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# -*- coding:utf-8 -*- | ||
# project_xxx\venv\Scripts python | ||
|
||
''' | ||
Author: Felix | ||
WeiXin: AXiaShuBai | ||
Email: [email protected] | ||
Blog: https://blog.csdn.net/u011318077 | ||
Date: 2020/1/31 14:17 | ||
Desc: | ||
''' | ||
|
||
# 首先导入绘图包和地图包 | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.basemap import Basemap | ||
|
||
# 第一步:设置图片大小及分辨率 | ||
plt.figure(figsize=(16, 8), dpi=128) | ||
|
||
# 第二步:创建一个地图 | ||
m = Basemap() | ||
|
||
# 第三步:绘制地图上的线条,比如海岸线,国界线 | ||
m.drawcoastlines(linewidth=1,linestyle='solid',color='black') # 绘制海岸线 | ||
m.drawcountries(linewidth=1,linestyle='solid',color='black') # 绘制国界线 | ||
|
||
# 第四步:显示图形 | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding:utf-8 -*- | ||
# project_xxx\venv\Scripts python | ||
|
||
''' | ||
Author: Felix | ||
WeiXin: AXiaShuBai | ||
Email: [email protected] | ||
Blog: https://blog.csdn.net/u011318077 | ||
Date: 2020/1/31 14:47 | ||
Desc: | ||
''' | ||
|
||
# 首先导入绘图包和地图包 | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.basemap import Basemap | ||
|
||
# 第一步:设置图片大小及分辨率 | ||
plt.figure(figsize=(16, 8), dpi=300) | ||
|
||
# 第二步:创建一个地图,设置经度纬度范围,只显示中国区域范围,projection选择投影模式 | ||
m = Basemap(llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51, projection='lcc', lat_1=33, lat_2=45, lon_0=100) | ||
# 读取中国行政区文件,使用国即组织GADM的地图文件,网站地址https://gadm.org/country | ||
# 大陆,台湾,港澳地区文件是分开的,都要进行读取,并且藏南地区和一些岛屿未标注出来 | ||
# 推荐使用案例003,网上已经整理好的中国地图文件 | ||
m.readshapefile('../china_shapfiles/gadm36_CHN_shp/gadm36_CHN_1', 'china', drawbounds=True) | ||
m.readshapefile('../china_shapfiles/gadm36_HKG_shp/gadm36_HKG_1', 'hkg', drawbounds=True) | ||
m.readshapefile('../china_shapfiles/gadm36_MAC_shp/gadm36_MAC_1', 'mac', drawbounds=True) | ||
m.readshapefile('../china_shapfiles/gadm36_TWN_shp/gadm36_TWN_1', 'twn', drawbounds=True) | ||
|
||
# m.readshapefile('../china_shapfiles/china-shapefiles-simple-version/china', 'china', drawbounds=True) | ||
|
||
# 上面使用读取了本地地图文件,就不需要使用basemap绘制海岸线和国界线了,避免混乱 | ||
# 第三步:绘制地图上的线条,比如海岸线,国界线 | ||
# m.drawcoastlines(linewidth=1,linestyle='solid',color='black') # 绘制海岸线 | ||
# m.drawcountries(linewidth=1,linestyle='solid',color='black') # 绘制国界线 | ||
|
||
# 第四步:显示图形 | ||
plt.show() |
34 changes: 34 additions & 0 deletions
34
basemap_matplotlib_使用案例/003_basemap_绘制中国地图_GitHub上的中国地图数据.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# -*- coding:utf-8 -*- | ||
# project_xxx\venv\Scripts python | ||
|
||
''' | ||
Author: Felix | ||
WeiXin: AXiaShuBai | ||
Email: [email protected] | ||
Blog: https://blog.csdn.net/u011318077 | ||
Date: 2020/1/31 15:31 | ||
Desc: | ||
''' | ||
# 首先导入绘图包和地图包 | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.basemap import Basemap | ||
|
||
# 第一步:设置图片大小及分辨率 | ||
plt.figure(figsize=(16, 8), dpi=300) | ||
|
||
# 第二步:创建一个地图,设置经度纬度范围,只显示中国区域范围,projection选择投影模式,兰勃特投影 | ||
m = Basemap(llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51, projection='lcc', lat_1=33, lat_2=45, lon_0=100) | ||
# 读取中国行政区文件,使用GitHub上已经整理好的地图文件,drawbounds参数显示图形 | ||
# 藏南区域和岛屿都有明显的标注,可以对比002结果,信息更加丰富,藏南更准确 | ||
m.readshapefile('../china_shapfiles/china-shapefiles-simple-version/china', 'china', drawbounds=True) | ||
# 九段线地图数据 | ||
m.readshapefile('../china_shapfiles/china-shapefiles-simple-version/china_nine_dotted_line', 'china', drawbounds=True) | ||
|
||
|
||
# 上面使用读取了本地地图文件,就不需要使用basemap绘制海岸线和国界线了,避免混乱 | ||
# 第三步:绘制地图上的线条,比如海岸线,国界线 | ||
# m.drawcoastlines(linewidth=1,linestyle='solid',color='black') # 绘制海岸线 | ||
# m.drawcountries(linewidth=1,linestyle='solid',color='black') # 绘制国界线 | ||
|
||
# 第四步:显示图形 | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding:utf-8 -*- | ||
# project_xxx\venv\Scripts python | ||
|
||
''' | ||
Author: Felix | ||
WeiXin: AXiaShuBai | ||
Email: [email protected] | ||
Blog: https://blog.csdn.net/u011318077 | ||
Date: 2020/1/31 16:38 | ||
Desc: | ||
''' | ||
import matplotlib.pyplot as plt | ||
from mpl_toolkits.basemap import Basemap | ||
from matplotlib.patches import Polygon | ||
|
||
# 第一步:设置图片大小及分辨率 | ||
plt.figure(figsize=(16, 8), dpi=300) | ||
|
||
# 第二步:创建一个地图,设置经度纬度范围,只显示中国区域范围,projection选择投影模式,兰勃特投影 | ||
m = Basemap(llcrnrlon=77, llcrnrlat=14, urcrnrlon=140, urcrnrlat=51, projection='lcc', lat_1=33, lat_2=45, lon_0=100) | ||
# 读取中国行政区文件,使用GitHub上已经整理好的地图文件,drawbounds参数显示图形 | ||
# 藏南区域和岛屿都有明显的标注,可以对比002结果,信息更加丰富,藏南更准确 | ||
m.readshapefile('../china_shapfiles/china-shapefiles-simple-version/china', 'china', drawbounds=True) | ||
# 九段线地图数据 | ||
m.readshapefile('../china_shapfiles/china-shapefiles-simple-version/china_nine_dotted_line', 'china_nine', drawbounds=True) | ||
|
||
# 第三步:上色 | ||
|
||
ax = plt.gca() | ||
|
||
for nshape, seg in enumerate(m.china): | ||
poly = Polygon(seg, facecolor='red', edgecolor='black') | ||
ax.add_patch(poly) | ||
|
||
|
||
|
||
|
||
# 第四步:显示图形 | ||
plt.show() | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions
57
nCov_basemap_visualization/nCov_basemap_matplotlib_visual.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding:utf-8 -*- | ||
# project_xxx\venv\Scripts python | ||
|
||
''' | ||
Author: Felix | ||
WeiXin: AXiaShuBai | ||
Email: [email protected] | ||
Blog: https://blog.csdn.net/u011318077 | ||
Date: 2020/1/31 17:18 | ||
Desc: | ||
''' | ||
|
||
import matplotlib.pyplot as plt | ||
from china_data_analysis import ChinaData | ||
|
||
# 显示中文和显示负号 | ||
plt.rcParams['font.sans-serif'] = ['SimHei'] | ||
plt.rcParams['axes.unicode_minus'] = False | ||
|
||
# 绘制画布和子图对象 | ||
fig, ax1 = plt.subplots(figsize=(10, 6)) | ||
|
||
# 获取每日疫情数据,日期,确诊,疑似,死亡,治愈 | ||
date_list, everyday_confirm, everyday_suspect, everyday_dead, everyday_heal = ChinaData().china_everyday_data() | ||
|
||
# 左Y轴绘制确诊和疑似病例曲线 | ||
ax1.plot(date_list, everyday_confirm, lw=2, ls='--', marker='o', color='red', label='确诊') | ||
ax1.plot(date_list, everyday_suspect, lw=2, ls='--', marker='o', color='orange', label='疑似') | ||
|
||
# 设置标题,XY轴标题,刻度 | ||
ax1.set_title("2019-nCoV疫情变化时间图", fontsize=16) | ||
ax1.set_xlabel("2020年1月", fontsize=16) | ||
ax1.set_xticklabels(date_list, rotation=30) | ||
ax1.set_ylabel(r"确诊及疑似人数", fontsize=16) | ||
ax1.set_ylim(0, 16000) | ||
# 显示网格线和显示图例 | ||
plt.grid(which='major', axis='both', color='grey', linestyle='--', alpha=0.2) | ||
plt.legend(loc='upper left', bbox_to_anchor=(0.3,1)) | ||
|
||
|
||
# 右Y轴绘制死亡和治愈病例曲线,共用ax1的X轴 | ||
ax2 = ax1.twinx() | ||
ax2.plot(date_list, everyday_dead, lw=1, ls='--', marker='.', color='cyan', label='死亡') | ||
ax2.plot(date_list, everyday_heal, lw=1, ls='--', marker='.', color='green', label='治愈') | ||
|
||
# 设置标题刻度 | ||
ax2.set_ylabel(r"死亡及治愈人数", fontsize=16) | ||
ax2.set_ylim(0, 400) | ||
# 显示网格线和显示图例 | ||
plt.grid(which='major', axis='both', color='grey', linestyle='--', alpha=0.2) | ||
plt.legend(loc='upper center') | ||
|
||
|
||
# 展示图形 | ||
# plt.show() | ||
# 保存图形为图片,第一个参数保存路径,第二个参数裁掉多余的空白部分 | ||
plt.savefig('2019-nCoV疫情变化时间图.png', bbox_inches='tight') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters