Python在氣象中的應(yīng)用

-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函數(shù)是地圖繪制的簡易封裝,需要中國的shp文件

if __name__ == '__main__':
    D = Draw_China()
    D.Draw()
map.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。
禁止轉(zhuǎn)載,如需轉(zhuǎn)載請通過簡信或評論聯(lián)系作者。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容