[Python] Ocean filler feature on Cartopy is not working

Discussão em 'Python' iniciado por Stack, Julho 20, 2025.

  1. Stack

    Stack Membro Participativo

    while trying to visualise a physical phenomenon on land, I am trying to make the ocean parts blue with ax.add_feature(cartopy.feature.OCEAN, zorder=1), but according to changing the zoder, either everywhere is blue or nowhere is blue, what exactly do you think is the reason for this?

    import matplotlib

    data_crs = ccrs.PlateCarree()
    sst = subs
    lats = latss
    lons = longss

    fig = plt.figure(figsize=(8,8))

    matplotlib.rcParams.update({'font.size': 14})
    central_lon, central_lat = 0, 90
    extent = [-180, 180, 90, 60]

    ax = plt.axes(projection=ccrs.NorthPolarStereo(central_lon))
    ax.set_extent(extent, ccrs.PlateCarree())


    ax.coastlines(resolution='10m', zorder=2)

    levels = np.linspace(-5,5,256)
    bounds=np.arange(-8,3,1)
    plot1 = plt.contourf(lons, lats, sst,256, levels=levels, cmap="RdYlBu",
    transform=data_crs, extend ="both", zorder=0)

    cbar = fig.colorbar(plot1,ax=ax,pad=0.1,shrink=0.6)
    cbar.set_label("meter",fontsize=14)
    cbar.set_ticks(np.arange(-5,6,1))
    cbar.ax.tick_params(labelsize=12)

    ax.add_feature(cartopy.feature.OCEAN, zorder=1)
    ax.gridlines(draw_labels=True,color="black", zorder=3)

    plt.savefig("EWT_v4.png",bbox_inches = 'tight', dpi=300, pad_inches = 0.02)


    [​IMG] [​IMG]

    Continue reading...

Compartilhe esta Página