• 【python海洋专题二十八】南海四季海流流速图


    【python海洋专题二十八】南海四季海流流速图
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

    往期推荐

    图片
    【python海洋专题一】查看数据nc文件的属性并输出属性到txt文件

    【python海洋专题二】读取水深nc文件并水深地形图
    【python海洋专题三】图像修饰之画布和坐标轴

    【Python海洋专题四】之水深地图图像修饰

    【Python海洋专题五】之水深地形图海岸填充

    【Python海洋专题六】之Cartopy画地形水深图

    【python海洋专题】测试数据

    【Python海洋专题七】Cartopy画地形水深图的陆地填充

    【python海洋专题八】Cartopy画地形水深图的contourf填充间隔数调整

    【python海洋专题九】Cartopy画地形等深线图

    【python海洋专题十】Cartopy画特定区域的地形等深线图

    【python海洋专题十一】colormap调色

    【python海洋专题十二】年平均的南海海表面温度图

    【python海洋专题十三】读取多个nc文件画温度季节变化图

    【python海洋专题十四】读取多个盐度nc数据画盐度季节变化图

    【python海洋专题十五】给colorbar加单位

    【python海洋专题十六】对大陆周边的数据进行临近插值

    【python海洋专题十七】读取几十年的OHC数据,画四季图

    【python海洋专题十八】读取Soda数据,画subplot的海表面高度四季变化图

    【python海洋专题十九】找范围的语句进阶版本

    【python海洋专题二十】subplots_adjust布局调整

    【python海洋专题二十一】subplots共用一个colorbar

    【python海洋专题二十二】在海图上text

    【python海洋专题二十三】共用坐标轴

    【python海洋专题二十四】南海年平均海流图

    【python海洋专题二十五】给南海年平均海流+scale

    【python海洋专题二十六】南海海流流速图

    【python海洋专题二十七】南海四季海流图

    【MATLAB海洋专题】历史汇总

    【matlab程序】图片平面制作||文末点赞分享||海报制作等

    大佬推荐一下物理海洋教材吧?

    【matlab海洋专题】高级玫瑰图–风速风向频率玫瑰图–此图细节较多

    
    # -*- coding: utf-8 -*-
    # ---导入数据读取和处理的模块-------
    from netCDF4 import Dataset
    from pathlib import Path
    import xarray as xr
    import numpy as np
    # ------导入画图相关函数--------
    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    import matplotlib.ticker as ticker
    from cartopy import mpl
    import cartopy.crs as ccrs
    import cartopy.feature as feature
    from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
    from pylab import *
    # -----导入颜色包---------
    import seaborn as sns
    from matplotlib import cm
    import palettable
    from palettable.cmocean.diverging import Delta_4
    from palettable.colorbrewer.sequential import GnBu_9
    from palettable.colorbrewer.sequential import Blues_9
    from palettable.scientific.diverging import Roma_20
    from palettable.cmocean.diverging import Delta_20
    from palettable.scientific.diverging import Roma_20
    from palettable.cmocean.diverging import Balance_20
    from matplotlib.colors import ListedColormap
    #     -------导入插值模块-----
    from scipy.interpolate import interp1d  # 引入scipy中的一维插值库
    from scipy.interpolate import griddata  # 引入scipy中的二维插值库
    from scipy.interpolate import interp2d
    
    
    # ----define reverse_colourmap定义颜色的反向函数----
    def reverse_colourmap(cmap, name='my_cmap_r'):
        reverse = []
        k = []
    
        for key in cmap._segmentdata:
            k.append(key)
            channel = cmap._segmentdata[key]
            data = []
    
            for t in channel:
                data.append((1 - t[0], t[2], t[1]))
            reverse.append(sorted(data))
    
        LinearL = dict(zip(k, reverse))
        my_cmap_r = mpl.colors.LinearSegmentedColormap(name, LinearL)
        return my_cmap_r
    
    
    # ---colormap的读取和反向----
    cmap01 = Balance_20.mpl_colormap
    cmap0 = Blues_9.mpl_colormap
    cmap_r = reverse_colourmap(cmap0)
    cmap1 = GnBu_9.mpl_colormap
    cmap_r1 = reverse_colourmap(cmap1)
    cmap2 = Roma_20.mpl_colormap
    cmap_r2 = reverse_colourmap(cmap2)
    # ---read_data---
    f1 = xr.open_dataset(r'E:\data\soda\soda3.12.2_5dy_ocean_reg_2017.nc')
    print(f1)
    # # 提取经纬度(这样就不需要重复读取)
    lat = f1['yt_ocean'].data
    lon = f1['xt_ocean'].data
    u = f1['u'].data
    v = f1['v'].data
    depth = f1['st_ocean'].data
    # print(depth)
    time = f1['time'].data
    # print(time)
    # # -------- find scs 's temp-----------
    ln1 = np.where(lon >= 100)[0][0]
    ln2 = np.where(lon >= 125)[0][0]
    la1 = np.where(lat >= 0)[0][0]
    la2 = np.where(lat >= 25)[0][0]
    # time_all=[(time>=1058760) & (time<=1059096)]   #13-27 Oct
    # # # 画图网格
    lon1 = lon[ln1:ln2]
    lat1 = lat[la1:la2]
    X, Y = np.meshgrid(lon1, lat1)
    u_aim = u[:, 0, la1:la2, ln1:ln2]
    v_aim = v[:, 0, la1:la2, ln1:ln2]
    # # # ----------对时间维度求平均 得到年平均的current------------------
    u_year_mean = np.mean(u_aim[:, :, :], axis=0)
    v_year_mean = np.mean(v_aim[:, :, :], axis=0)
    # ------春夏秋冬------
    u_spr_mean = np.mean(u_aim[2:5, :, :], axis=0)
    u_sum_mean = np.mean(u_aim[5:8, :, :], axis=0)
    u_atu_mean = np.mean(u_aim[8:11, :, :], axis=0)
    u_win_mean = (u_aim[0, :, :] + u_aim[1, :, :] + u_aim[11, :, :]) / 3
    v_spr_mean = np.mean(v_aim[2:5, :, :], axis=0)
    v_sum_mean = np.mean(v_aim[5:8, :, :], axis=0)
    v_atu_mean = np.mean(v_aim[8:11, :, :], axis=0)
    v_win_mean = (v_aim[0, :, :] + v_aim[1, :, :] + v_aim[11, :, :]) / 3
    w_spr_mean_new = np.sqrt(np.square(u_spr_mean) + np.square(v_spr_mean))
    w_sum_mean_new = np.sqrt(np.square(u_sum_mean) + np.square(v_sum_mean))
    w_atu_mean_new = np.sqrt(np.square(u_atu_mean) + np.square(v_atu_mean))
    w_win_mean_new = np.sqrt(np.square(u_win_mean) + np.square(v_win_mean))
    # ----plot--------------
    scale = '50m'
    plt.rcParams['font.sans-serif'] = ['Times New Roman']  # 设置整体的字体为Times New Roman
    # 设置显示中文字体
    mpl.rcParams["font.sans-serif"] = ["SimHei"]
    mpl.rcParams["mathtext.fontset"] = 'cm'  # 数学文字字体
    mpl.rcParams["font.size"] = 12  # 字体大小
    mpl.rcParams["axes.linewidth"] = 1  # 轴线边框粗细(默认的太粗了)
    fig = plt.figure(dpi=300, figsize=(3.5, 2.6), facecolor='w', edgecolor='blue')  # 设置一个画板,将其返还给fig
    # 通过subplots_adjust()设置间距配置
    fig.subplots_adjust(left=0.06, bottom=0.05, right=0.85, top=0.95, wspace=0.01, hspace=0.15)
    # --------第一个子图----------
    ax = fig.add_subplot(2, 2, 1, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_spr_mean, v_spr_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_spr_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('春季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    # plt.yticks([])
    plt.xticks([])
    # -----第二个子图# --------子图----------
    ax = fig.add_subplot(2, 2, 2, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_sum_mean, v_sum_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_sum_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('夏季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    plt.yticks([])
    plt.xticks([])
    # -----第san个子图# --------子图----------
    ax = fig.add_subplot(2, 2, 3, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_atu_mean, v_atu_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_atu_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('秋季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    # plt.yticks([])
    # plt.xticks([])
    # -----第四个子图# --------子图----------
    ax = fig.add_subplot(2, 2, 4, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_win_mean, v_win_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_win_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('冬季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    # % 不显示坐标刻度
    plt.yticks([])
    # plt.xticks([])
    # ---------共用colorbar------
    cb_ax = fig.add_axes([0.85, 0.1, 0.02, 0.8])  #设置colarbar位置
    cbar = fig.colorbar(cf, cax=cb_ax, ax=ax, extend='both', orientation='vertical', ticks=[0, 0.2, 0.4, 0.6, 0.8, 1.0])     #共享colorbar
    plt.savefig('subplot_current_45.jpg', dpi=600, bbox_inches='tight', pad_inches=0.1)  # 输出地图,并设置边框空白紧密
    plt.show()
    2
    
    # -*- coding: utf-8 -*-
    # ---导入数据读取和处理的模块-------
    from netCDF4 import Dataset
    from pathlib import Path
    import xarray as xr
    import numpy as np
    # ------导入画图相关函数--------
    import matplotlib.pyplot as plt
    from matplotlib.font_manager import FontProperties
    import matplotlib.ticker as ticker
    from cartopy import mpl
    import cartopy.crs as ccrs
    import cartopy.feature as feature
    from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
    from pylab import *
    # -----导入颜色包---------
    import seaborn as sns
    from matplotlib import cm
    import palettable
    from palettable.cmocean.diverging import Delta_4
    from palettable.colorbrewer.sequential import GnBu_9
    from palettable.colorbrewer.sequential import Blues_9
    from palettable.scientific.diverging import Roma_20
    from palettable.cmocean.diverging import Delta_20
    from palettable.scientific.diverging import Roma_20
    from palettable.cmocean.diverging import Balance_20
    from matplotlib.colors import ListedColormap
    #     -------导入插值模块-----
    from scipy.interpolate import interp1d  # 引入scipy中的一维插值库
    from scipy.interpolate import griddata  # 引入scipy中的二维插值库
    from scipy.interpolate import interp2d
    
    
    # ----define reverse_colourmap定义颜色的反向函数----
    def reverse_colourmap(cmap, name='my_cmap_r'):
        reverse = []
        k = []
    
        for key in cmap._segmentdata:
            k.append(key)
            channel = cmap._segmentdata[key]
            data = []
    
            for t in channel:
                data.append((1 - t[0], t[2], t[1]))
            reverse.append(sorted(data))
    
        LinearL = dict(zip(k, reverse))
        my_cmap_r = mpl.colors.LinearSegmentedColormap(name, LinearL)
        return my_cmap_r
    
    
    # ---colormap的读取和反向----
    cmap01 = Balance_20.mpl_colormap
    cmap0 = Blues_9.mpl_colormap
    cmap_r = reverse_colourmap(cmap0)
    cmap1 = GnBu_9.mpl_colormap
    cmap_r1 = reverse_colourmap(cmap1)
    cmap2 = Roma_20.mpl_colormap
    cmap_r2 = reverse_colourmap(cmap2)
    # ---read_data---
    f1 = xr.open_dataset(r'E:\data\soda\soda3.12.2_5dy_ocean_reg_2017.nc')
    print(f1)
    # # 提取经纬度(这样就不需要重复读取)
    lat = f1['yt_ocean'].data
    lon = f1['xt_ocean'].data
    u = f1['u'].data
    v = f1['v'].data
    depth = f1['st_ocean'].data
    # print(depth)
    time = f1['time'].data
    # print(time)
    # # -------- find scs 's temp-----------
    ln1 = np.where(lon >= 100)[0][0]
    ln2 = np.where(lon >= 125)[0][0]
    la1 = np.where(lat >= 0)[0][0]
    la2 = np.where(lat >= 25)[0][0]
    # time_all=[(time>=1058760) & (time<=1059096)]   #13-27 Oct
    # # # 画图网格
    lon1 = lon[ln1:ln2]
    lat1 = lat[la1:la2]
    X, Y = np.meshgrid(lon1, lat1)
    u_aim = u[:, 0, la1:la2, ln1:ln2]
    v_aim = v[:, 0, la1:la2, ln1:ln2]
    # # # ----------对时间维度求平均 得到年平均的current------------------
    u_year_mean = np.mean(u_aim[:, :, :], axis=0)
    v_year_mean = np.mean(v_aim[:, :, :], axis=0)
    # ------春夏秋冬------
    u_spr_mean = np.mean(u_aim[2:5, :, :], axis=0)
    u_sum_mean = np.mean(u_aim[5:8, :, :], axis=0)
    u_atu_mean = np.mean(u_aim[8:11, :, :], axis=0)
    u_win_mean = (u_aim[0, :, :] + u_aim[1, :, :] + u_aim[11, :, :]) / 3
    v_spr_mean = np.mean(v_aim[2:5, :, :], axis=0)
    v_sum_mean = np.mean(v_aim[5:8, :, :], axis=0)
    v_atu_mean = np.mean(v_aim[8:11, :, :], axis=0)
    v_win_mean = (v_aim[0, :, :] + v_aim[1, :, :] + v_aim[11, :, :]) / 3
    w_spr_mean_new = np.sqrt(np.square(u_spr_mean) + np.square(v_spr_mean))
    w_sum_mean_new = np.sqrt(np.square(u_sum_mean) + np.square(v_sum_mean))
    w_atu_mean_new = np.sqrt(np.square(u_atu_mean) + np.square(v_atu_mean))
    w_win_mean_new = np.sqrt(np.square(u_win_mean) + np.square(v_win_mean))
    # ----plot--------------
    scale = '50m'
    plt.rcParams['font.sans-serif'] = ['Times New Roman']  # 设置整体的字体为Times New Roman
    # 设置显示中文字体
    mpl.rcParams["font.sans-serif"] = ["SimHei"]
    mpl.rcParams["mathtext.fontset"] = 'cm'  # 数学文字字体
    mpl.rcParams["font.size"] = 12  # 字体大小
    mpl.rcParams["axes.linewidth"] = 1  # 轴线边框粗细(默认的太粗了)
    fig = plt.figure(dpi=300, figsize=(3.5, 2.6), facecolor='w', edgecolor='blue')  # 设置一个画板,将其返还给fig
    # 通过subplots_adjust()设置间距配置
    fig.subplots_adjust(left=0.05, bottom=0.05, right=0.9, top=0.95, wspace=0.05, hspace=0.15)
    # --------第一个子图----------
    ax = fig.add_subplot(2, 2, 1, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_spr_mean, v_spr_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_spr_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    # ------color-bar设置------------
    cb = plt.colorbar(cf, ax=ax, extend='both', orientation='vertical', ticks=np.linspace(0, 1, 6))
    cb.ax.tick_params(labelsize=4, direction='in')  # 设置color-bar刻度字体大小。
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('春季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    # -----第二个子图# --------子图----------
    ax = fig.add_subplot(2, 2, 2, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_sum_mean, v_sum_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_sum_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    # ------color-bar设置------------
    cb = plt.colorbar(cf, ax=ax, extend='both', orientation='vertical', ticks=np.linspace(0, 1, 6))
    cb.set_label('current_size', fontsize=4, color='k')  # 设置color-bar的标签字体及其大小
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('夏季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    # -----第san个子图# --------子图----------
    ax = fig.add_subplot(2, 2, 3, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_atu_mean, v_atu_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_atu_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    # ------color-bar设置------------
    cb = plt.colorbar(cf, ax=ax, extend='both', orientation='vertical', ticks=np.linspace(0, 1, 6))
    cb.ax.tick_params(labelsize=4, direction='in')  # 设置color-bar刻度字体大小。
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('秋季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    # -----第四个子图# --------子图----------
    ax = fig.add_subplot(2, 2, 4, projection=ccrs.PlateCarree(central_longitude=180))
    ax.set_extent([100, 123, 0, 25], crs=ccrs.PlateCarree())  # 设置显示范围
    land = feature.NaturalEarthFeature('physical', 'land', scale, edgecolor='face', zorder=1,
                                       facecolor=feature.COLORS['land'])
    ax.add_feature(land, facecolor='0.6')
    ax.add_feature(feature.COASTLINE.with_scale('50m'), lw=0.3, zorder=2)  # 添加海岸线:关键字lw设置线宽; lifestyle设置线型
    cs = ax.quiver(X, Y, u_win_mean, v_win_mean, color='r', scale=5, zorder=1, width=0.003, headwidth=3,
                   headlength=4.5, transform=ccrs.PlateCarree())
    cf = ax.contourf(X, Y, w_win_mean_new, extend='both', zorder=0, cmap=cmap_r2, levels=np.linspace(0, 1, 50),
                     transform=ccrs.PlateCarree())  #
    # ------color-bar设置------------
    cb = plt.colorbar(cf, ax=ax, extend='both', orientation='vertical', ticks=np.linspace(0, 1, 6))
    cb.set_label('current_size', fontsize=4, color='k')  # 设置color-bar的标签字体及其大小
    font = {'family': 'serif',
            'weight': 'normal',
            'size': 4,
            }
    ax.quiverkey(cs,  # 传入quiver句柄
                 X=0.9, Y=1.015,  # 确定 label 所在位置,都限制在[0,1]之间
                 U=0.5,  # 参考箭头长度 表示风速为5m/s。
                 angle=0,  # 参考箭头摆放角度。默认为0,即水平摆放
                 label='0.5m/s',  # 箭头的补充:label的内容  +
                 labelsep=0.01,
                 labelpos='N',  # label在参考箭头的哪个方向; S表示南边
                 color='r', labelcolor='r',  # 箭头颜色 + label的颜色
                 fontproperties=font,  # l abel 的字体设置:大小,样式,weight
                 zorder=10,
                 )
    # --------------添加标题----------------
    ax.set_title('冬季', loc="center", fontsize=6, pad=1)
    # ------------------利用Formatter格式化刻度标签-----------------
    ax.set_xticks(np.arange(100, 123, 5), crs=ccrs.PlateCarree())  # 添加经纬度
    ax.set_xticklabels(np.arange(100, 123, 5), fontsize=4)
    ax.set_yticks(np.arange(0, 25, 5), crs=ccrs.PlateCarree())
    ax.set_yticklabels(np.arange(0, 25, 5), fontsize=4)
    ax.xaxis.set_major_formatter(LongitudeFormatter())
    ax.yaxis.set_major_formatter(LatitudeFormatter())
    ax.tick_params(axis='x', top=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 刻度样式  pad代表标题离轴的远近
    ax.tick_params(axis='y', right=True, which='major', direction='in', length=3, width=0.8, labelsize=5, pad=0.8,
                   color='k')  # 更改刻度指向为朝内,颜色设置为蓝色
    gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=False, xlocs=np.arange(100, 123, 5), ylocs=np.arange(0, 25, 5),
                      linewidth=0.25, linestyle='--', color='k', alpha=0.8)  # 添加网格线
    gl.top_labels, gl.bottom_labels, gl.right_labels, gl.left_labels = False, False, False, False
    plt.savefig('subplot_current_3.jpg', dpi=600, bbox_inches='tight', pad_inches=0.1)  # 输出地图,并设置边框空白紧密
    plt.show()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
    • 155
    • 156
    • 157
    • 158
    • 159
    • 160
    • 161
    • 162
    • 163
    • 164
    • 165
    • 166
    • 167
    • 168
    • 169
    • 170
    • 171
    • 172
    • 173
    • 174
    • 175
    • 176
    • 177
    • 178
    • 179
    • 180
    • 181
    • 182
    • 183
    • 184
    • 185
    • 186
    • 187
    • 188
    • 189
    • 190
    • 191
    • 192
    • 193
    • 194
    • 195
    • 196
    • 197
    • 198
    • 199
    • 200
    • 201
    • 202
    • 203
    • 204
    • 205
    • 206
    • 207
    • 208
    • 209
    • 210
    • 211
    • 212
    • 213
    • 214
    • 215
    • 216
    • 217
    • 218
    • 219
    • 220
    • 221
    • 222
    • 223
    • 224
    • 225
    • 226
    • 227
    • 228
    • 229
    • 230
    • 231
    • 232
    • 233
    • 234
    • 235
    • 236
    • 237
    • 238
    • 239
    • 240
    • 241
    • 242
    • 243
    • 244
    • 245
    • 246
    • 247
    • 248
    • 249
    • 250
    • 251
    • 252
    • 253
    • 254
    • 255
    • 256
    • 257
    • 258
    • 259
    • 260
    • 261
    • 262
    • 263
    • 264
    • 265
    • 266
    • 267
    • 268
    • 269
    • 270
    • 271
    • 272
    • 273
    • 274
    • 275
    • 276
    • 277
    • 278
    • 279
    • 280
    • 281
    • 282
    • 283
    • 284
    • 285
    • 286
    • 287
    • 288
    • 289
    • 290
    • 291
    • 292
    • 293
    • 294
    • 295
    • 296
    • 297
    • 298
    • 299
    • 300
    • 301
    • 302
    • 303
    • 304
    • 305
    • 306
    • 307
    • 308
    • 309
    • 310
    • 311
    • 312
    • 313
    • 314
    • 315
    • 316
    • 317
    • 318
    • 319
    • 320
    • 321
    • 322
    • 323
    • 324
    • 325
    • 326
    • 327
    • 328
    • 329
    • 330
    • 331
    • 332
    • 333
    • 334
    • 335
    • 336
    • 337
    • 338
    • 339
    • 340
    • 341
    • 342
    • 343
    • 344
    • 345
    • 346
    • 347
    • 348
    • 349
    • 350
    • 351
    • 352
    • 353
    • 354
    • 355
    • 356
    • 357
    • 358
    • 359
    • 360
    • 361
    • 362
    • 363
    • 364
    • 365
    • 366
    • 367
    • 368
    • 369
    • 370
    • 371
    • 372
    • 373
    • 374
    • 375
    • 376
    • 377
    • 378
    • 379
    • 380
    • 381
    • 382
    • 383
    • 384
    • 385
    • 386
    • 387
    • 388
    • 389
    • 390
    • 391
    • 392
    • 393
    • 394
    • 395
    • 396
    • 397
    • 398
    • 399
    • 400
    • 401
    • 402
    • 403
    • 404
    • 405
    • 406
    • 407
    • 408
    • 409
    • 410
    • 411
    • 412
    • 413
    • 414
    • 415
    • 416
    • 417
    • 418
    • 419
    • 420
    • 421
    • 422
    • 423
    • 424
    • 425
    • 426
    • 427
    • 428
    • 429
    • 430
    • 431
    • 432
    • 433
    • 434
    • 435
    • 436
    • 437
    • 438
    • 439
    • 440
    • 441
    • 442
    • 443
    • 444
    • 445
    • 446
    • 447
    • 448
    • 449
    • 450
    • 451
    • 452
    • 453
    • 454
    • 455
    • 456
    • 457
    • 458
    • 459
    • 460
    • 461
    • 462
    • 463
    • 464
    • 465
    • 466
    • 467
    • 468
    • 469
    • 470
    • 471
    • 472
    • 473
    • 474
    • 475
    • 476
    • 477
    • 478
    • 479
    • 480
    • 481
    • 482
    • 483
    • 484
    • 485
    • 486
    • 487
    • 488
    • 489
    • 490
    • 491
    • 492
    • 493
    • 494
    • 495
    • 496
    • 497
    • 498
    • 499
    • 500
    • 501
    • 502
    • 503
    • 504
    • 505
    • 506
    • 507
    • 508
    • 509
    • 510
    • 511
    • 512
    • 513
    • 514
    • 515
    • 516
    • 517
    • 518
    • 519
    • 520
    • 521
    • 522
    • 523
    • 524
    • 525
    • 526
    • 527
    • 528
    • 529
    • 530
    • 531
    • 532
    • 533
    • 534
    • 535
    • 536
    • 537
    • 538
    • 539
    • 540
    • 541
    • 542
    • 543
    • 544
    • 545
    • 546
    • 547
    • 548
    • 549
    • 550
    • 551
    • 552
    • 553
    • 554
    • 555
    • 556
    • 557
    • 558
    • 559
    • 560
    • 561
    • 562
    • 563
    • 564
    • 565
    • 566
    • 567
    • 568
    • 569
    • 570
    • 571
    • 572
    • 573
    • 574
    • 575
    • 576
    • 577
    • 578
    • 579
    • 580
    • 581
    • 582
    • 583
    • 584
    • 585
    • 586
    • 587
    • 588
    • 589
  • 相关阅读:
    基于 MinIO 对象存储保障 Rancher 数据
    C++初阶 | [四] 类和对象(下)
    SpringBoot学习笔记(五)——Git版本控制
    __attribute__ 高级运用
    MongoDB聚合运算符:$sinh
    uniapp 小程序 身份证 和人脸视频拍摄
    react配置 axios
    磺酸修饰/单分散氢氧化钙/聚苯乙烯微球/载对苯二酚聚苯乙烯-二乙烯苯交联微球的性能
    腾讯云COS+Picgo+Typora图床搭建
    自定义拖拽操作
  • 原文地址:https://blog.csdn.net/miaobo0/article/details/133985512