-2- 绘制世界地图、中国地图
class Draw_China():
'''
Function:This script is used to map China.
Author:xiaohuoya
Date:2022-05-25
'''
def __init__(self):
self.china_shp = './shp/china.shp'
self.fs = 10
self.cl = 'k'
def Draw(self):
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
from cartopy.io.shapereader import Reader
def Map_China(ax):
ax.set_extent([-180,180,-90,90])
ax.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.3)
ax.add_feature(cfeature.OCEAN.with_scale('50m'), linewidth=0.3)
ax.add_feature(cfeature.LAND.with_scale('50m'), linewidth=0.3)
ax.add_feature(cfeature.LAKES.with_scale('50m'), linewidth=0.3)
ax.add_geometries(Reader(self.china_shp).geometries(),
ccrs.PlateCarree(), facecolor='none', edgecolor='k', linewidth=0.3)
lb = ax.gridlines(draw_labels=True, x_inline=False, y_inline=False,
linewidth=0.1, color='gray', alpha=0.8, linestyle='--')
lb.top_labels = False
lb.right_labels = None
lb.xlocator = mticker.FixedLocator(
range(-180,180, 40))
lb.ylocator = mticker.FixedLocator(
range(-90,90, 30))
lb.ylabel_style = {'size': self.fs, 'color': self.cl}
lb.xlabel_style = {'size': self.fs, 'color': self.cl}
lb.rotate_labels = False
fig = plt.figure(figsize=(10, 10))
proj = ccrs.PlateCarree()
ax = fig.add_subplot(1, 1, 1, projection=proj)
Map_China(ax)
plt.savefig('./output/map.png')
1.Map_China函数是地图绘制的简易封装,需要中国的shp文件
if __name__ == '__main__':
D = Draw_China()
D.Draw()
map.png