Python在氣象中的應用

-3- 繪制中國地圖進階版本

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 = 6
        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([60, 160, 0, 60])
            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(60, 160, 20))
            lb.ylocator = mticker.FixedLocator(
                range(0, 90, 15))
            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), dpi=300)
        proj = ccrs.PlateCarree()
        ax = fig.add_subplot(1, 1, 1, projection=proj)
        Map_China(ax)
        ax.set_title('Fig1:  Made in xiaohuoya',
                     fontsize=self.fs, loc='left')
        f_x = [105, 122, 122, 105, 105]
        f_y = [26, 26, 32, 32, 26]
        ax.plot(f_x, f_y, color='r', linestyle='--', linewidth=0.5)
        f1_x = [100, 127, 127, 100, 100]
        f2_y = [20, 20, 38, 38, 20]
        ax.plot(f1_x, f2_y, color='r', linestyle='-', linewidth=1)

        ax2 = plt.axes([0.25, 0.6, 0.3, 0.3], projection=proj)  # 左下寬高
        ax2.set_extent([105, 122, 26, 32])
        ax2.add_feature(cfeature.COASTLINE.with_scale('50m'), linewidth=0.3)
        ax2.add_feature(cfeature.OCEAN.with_scale('50m'), linewidth=0.3)
        ax2.add_feature(cfeature.LAND.with_scale('50m'), linewidth=0.3)
        ax2.add_feature(cfeature.LAKES.with_scale('50m'), linewidth=0.3)
        ax2.add_geometries(Reader(self.china_shp).geometries(),
                           ccrs.PlateCarree(), facecolor='none', edgecolor='k', linewidth=0.3)
        lb = ax2.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(
            [105, 109, 113, 117, 121])
        lb.ylocator = mticker.FixedLocator(
            [26, 28, 30, 32, 34])
        lb.ylabel_style = {'size': 4, 'color': 'k'}
        lb.xlabel_style = {'size': 4, 'color': 'k'}
        lb.rotate_labels = False
        ax.arrow(113.5, 32, -11.5, 12, head_width=3.5,
                 head_length=5.5, ec='r', fc='r', color='red', width=0.8)

        plt.show()


if __name__ == '__main__':
    D = Draw_China()
    D.Draw()

1.增添子圖的疊加
2.增添線條、箭頭的繪制
3.子圖的添加實際上就是在第一張圖的頂層在繪制一張圖


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

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

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