Skip to content

Matplotlib Visualization Examples #37

Description

@philipc2

@guoqing-noaa

We've made some recent efforts since the last time we met regarding better support for native Cartopy + Matplotlib workflows. I'm sure @erogluorhan has mentioned this, but here are a few examples that might be helpful while developing the cook-book.

fig, ax = plt.subplots(
    subplot_kw={'projection': ccrs.Orthographic(central_longitude=-90, central_latitude=45)},
    constrained_layout=True,
    figsize=(10, 5),
)
scale = '110m'


ax.set_extent([-90, -80, 40, 50])  # great lakes 

var = uxds['lwupt'].isel(Time=0)

raster = var.to_raster(ax=ax)

my_plot = ax.imshow(raster, origin='lower', extent=ax.get_xlim() + ax.get_ylim())


ax.coastlines(resolution=scale, color='black', linewidth=1)
ax.add_feature(cfeature.BORDERS.with_scale(scale), linestyle=':', linewidth=0.8)
ax.add_feature(cfeature.STATES.with_scale(scale), linestyle=':', linewidth=0.8)
gl = ax.gridlines(
    draw_labels=True,
    linewidth=0.5,
    linestyle='--',
    color='gray',
    alpha=0.7,
)

lakes = NaturalEarthFeature(
    category='physical',
    name='lakes',
    scale='10m',
    edgecolor='black',
    facecolor='none',
    alpha=0.7,
)
ax.add_feature(lakes, linewidth=1, zorder=2)

gl.top_labels = False
gl.right_labels = False

ax.set_title(f"15km MPAS: {var.long_name}", pad=4, fontsize=10)

cbar = fig.colorbar(
    my_plot,
    ax=ax,
    orientation='vertical',
    shrink=0.6,
    pad=0.03,
)
label = rf"$\mathit{{{var.name}}}\ \left[\mathrm{{{var.units}}}\right]$"
cbar.set_label(label, labelpad=8, fontsize=12)

plt.show()
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    contentContent related issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions