Python在气象中的应用

-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
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容