cart.set_grid_ticks( ax1, projection=ccrs.PlateCarree(), xticks=[0, 45, 90, 135, -360, -180, -135, -90, -45 - 0], yticks=[-60, -40, -20, 0, 20, 40, 60], xlabels=False, ylabels=True, grid=False, fontsize=12, color="black", ) cart.subplot_label( ax1, xdist_label=0.1, ydist_label=0.86, subplot_label="A", form="box", fs_shade=28, fs_main=18, color="black", ) ############## Subplot 2 ################# cart.set_subplots(ax2, projection, resolution, lon_min=-180, lon_max=179, lat_min=-66, lat_max=66) cs2 = ax2.pcolormesh( lon,
cart.set_grid_ticks( ax1, projection=ccrs.PlateCarree(), xticks=xticks, yticks=yticks, xlabels=False, ylabels=True, grid=True, fontsize=20, color="black", ) cart.subplot_label( ax1, xdist_label=0.1, ydist_label=0.88, subplot_label="A", form="box", fs_shade=35, fs_main=25, color=None, ) ############## Moderately Restrictive ################# cart.set_subplots(ax2, projection, resolution, lon_min=-180, lon_max=179, lat_min=-66, lat_max=66) # North indian ocean high
cs1, cax1, fig, orientation="horizontal", extend="both", cbar_label="$m\,s^{-1}$", nbins=7, fontsize=20, cbar_ticks=[], task="regular", ) cart.subplot_label( ax1, xdist_label=0.1, ydist_label=0.88, subplot_label="A", form="box", fs_shade=28, fs_main=20, color="black", ) # Set regional climatology grid box ax1.add_patch( mpatches.Rectangle( xy=[108, -31], width=4, height=4, edgecolor="black", facecolor=None, linestyle="-", linewidth=2,
cs1, cax1, fig, orientation="horizontal", extend="min", cbar_label="$\%$", nbins=6, fontsize=14, cbar_ticks=[], task="regular", ) cart.subplot_label( ax1, xdist_label=0.1, ydist_label=0.86, subplot_label="A", form="box", fs_shade=28, fs_main=18, color="black", ) cart.subplot_label( ax1, xdist_label=0.24, ydist_label=0.86, subplot_label="DJF", form="box", fs_shade=28, fs_main=18, color="black", )
orientation="vertical", extend="both", cbar_label="$months$", nbins=7, fontsize=15, cbar_ticks=[ np.arange(-np.pi, np.pi + 0.5, (np.pi + np.pi) / 6).tolist(), ["", "Jun", "Aug", "Oct", "Dec", "Feb", "Apr", "Jun"], ], task="custom ticks", ) cart.subplot_label( ax1, xdist_label=0.05, ydist_label=0.9, subplot_label="A", form="box", fs_shade=28, fs_main=18, color="black", ) # Place minor islands on map. This requires a working NaturalEarthFeature installation from cartopy. If you have that, # you may uncomment this line: # ax1.add_feature(cfeature.NaturalEarthFeature('physical', 'minor_islands', resolution)) # Set grid boxes for wave shadowing ax1.add_patch( mpatches.Rectangle( xy=[176, -18], width=6, height=5,
def regional_clima_plot( ax, swh_mean, swh_stdm, swh_hfit, wsp_mean, wsp_stdm, wsp_hfit, swh_model_mean, swh_model_stdm, wsp_model_mean, wsp_model_stdm, time, time_ticks, xlim, ylim, subplot_label, fontsize, linewidth, task, grid=True, ): """ region_clima_plot(ax, swh_mean, swh_stdm, swh_hfit, wsp_mean, wsp_stdm, wsp_hfit, swh_model_mean, swh_model_stdm, wsp_model_mean, wsp_model_stdm, time, time_ticks, xlim, ylim, subplot_label, fontsize, linewidth, task, grid=True) Function for plotting regional climatologies on a subplot. Parameters ---------- ax : Geospatial axes for the subplot ex: fig, axes = plt.subplots(3, 2, figsize=(16,12),subplot_kw={'projection': projection}) ax1, ax2, ax3, ax4, ax5, ax6 = axes.flatten() swh_mean : Ifremer SWH regional climatology mean swh_stdm : Ifremer SWH regional climatology standard error of the mean swh_hfit : Ifremer SWH regional climatology lsf model wsp_mean : CCMP v2 regional climatology mean wsp_stdm : CCMP v2 regional climatology standard error of the mean wsp_hfit : CCMP v2 regional climatology lsf model swh_model_mean : WW3 swh regional climatology mean swh_model_stdm : WW3 swh regional climatology standard error of the mean wsp_model_mean : WW3 wsp regional climatology mean wsp_model_stdm : WW3 wsp regional climatology standard error of the mean time : time vector for plotting regional climatologies ex: time = np.arange(0,13) time_ticks : tick labels for subplot ex: time_ticks = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] xlim : x_axis limits in list form ex: xlim = [0,13] ylim : y axis lims for both axes in the form of a list: ylim = [[swh_limits], [wsp_limits]] ex: ylim = [[1,4], [6, 10]] subplot_label : subplot label for paper ex: subplot_label = 'A' fontsize : Specifies the font size of the x and y tickmarks as well as the x and y axes labels. ex: fontsize = 15 linewidth : Specifies the line width for the line plot. ex: linewidth = 2 task : Specifies whether the plot will be displaying WW3, Ifremer, and CCMP2 comparision (ww3), Ifremer and CCMP2 climatology only with models (IC), residual of SWH with CCMP2 climatology (residual), or Ifremer and CCMP2 comparison with swh residual (C_I_res). Options include: task = 'ww3' or task = 'IC', task = 'residual', task = 'C_I_res'. grid : Specifies if the subplot has a grid or not. By default, grid == True meaning a grid is plotted. grid == False removes the grid on the figure. Returns ------- Plots regional climatology subplot from specified region Libraries necessary to run function ----------------------------------- import numpy as np import matplotlib.pyplot as plt import cartopy_fig_module as cart """ # Path to access python functions import sys sys.path.append("../tools/") # import libraries: import numpy as np import matplotlib.pyplot as plt # Import my function import cartopy_figs as cart ########## SWH ########## # Set axis: ax_twin = ax.twinx() # set axis color: color = "tab:blue" ax_twin.tick_params(axis="y", labelcolor=color) # WW3 comparison if task == "ww3": # Plot WW3 ax_twin.plot(time, swh_model_mean, ".--b", color="tab:blue", linewidth=linewidth) ax_twin.plot(time, swh_model_mean, ".b", color="tab:blue", markersize=2) ax_twin.fill_between( time, swh_model_mean - swh_model_stdm, swh_model_mean + swh_model_stdm, color="tab:blue", alpha=0.3, ) # Plot Ifremer SWH ax_twin.plot(time, swh_mean, ".-b", linewidth=linewidth) ax_twin.plot(time, swh_mean, ".b", markersize=2) ax_twin.fill_between(time, swh_mean - swh_stdm, swh_mean + swh_stdm, color="blue", alpha=0.3) # Ifremer-CCMP2 comparison elif task == "IC": # Plot Ifremer SWH and lsf model ax_twin.plot(time, swh_mean, ".-b", linewidth=linewidth) ax_twin.plot(time, swh_mean, ".b", markersize=2) ax_twin.plot(time, swh_hfit, ".--b", linewidth=linewidth) ax_twin.plot(time, swh_hfit, ".b", markersize=2) ax_twin.fill_between(time, swh_mean - swh_stdm, swh_mean + swh_stdm, color=color, alpha=0.3) # Ifremer-CCMP2 residual comparison elif task == "residual": # Compute residual res_swh = swh_hfit - swh_mean # Plot Ifremer SWH residual ax_twin.plot(time, res_swh, ".-b", linewidth=linewidth) ax_twin.plot(time, res_swh, ".b", markersize=2) ax_twin.fill_between(time, 0, res_swh, facecolor="blue", alpha=0.2) # Ifremer-CCMP2 comparison and residual elif task == "C_I_res": # Plot Ifremer SWH and lsf model ax_twin.plot(time, swh_mean, ".-b", linewidth=linewidth) ax_twin.plot(time, swh_mean, ".b", markersize=2) ax_twin.plot(time, swh_hfit, ".--b", linewidth=linewidth) ax_twin.plot(time, swh_hfit, ".b", markersize=2) ax_twin.fill_between(time, swh_mean - swh_stdm, swh_mean + swh_stdm, color=color, alpha=0.3) # Compute residual res_swh = swh_mean - swh_hfit # Plot Ifremer SWH residual ax_twin.plot(time, res_swh, ".-k", linewidth=linewidth) ax_twin.plot(time, res_swh, ".k", markersize=2) ax_twin.fill_between(time, 0, res_swh, facecolor="black", alpha=0.2) # set SWH y-axis attributes: if task == "residual": ax_twin.set_ylabel("$Residual\;SWH\;m$", color=color, fontsize=fontsize) ax_twin.set_ylim(ylim[0]) elif task == "C_I_res": ax_twin.set_ylabel("$m$", color=color, fontsize=fontsize) ax_twin.set_yticks(np.arange(ylim[0][0], ylim[0][1] + 0.5, 0.5)) for label in ax_twin.yaxis.get_ticklabels()[1::2]: label.set_visible(False) else: ax_twin.set_ylabel("$SWH\;(m)$", color=color, fontsize=fontsize) ax_twin.set_ylim(ylim[0]) ax_twin.tick_params(axis="y", labelsize=fontsize) # Set grid lines if grid == True: ax_twin.grid(color=color, linestyle="-.", linewidth=1, alpha=0.35) ########## WSP ########## # set color: color = "tab:red" ax.tick_params(axis="y", labelcolor=color) # WW3 comparison if task == "ww3": # plot WW3 WSP ax.plot(time, wsp_model_mean, ".--", color="tab:red", linewidth=linewidth) ax.plot(time, wsp_model_mean, ".", color="tab:red", markersize=2) ax.fill_between( time, wsp_model_mean - wsp_model_stdm, wsp_model_mean + wsp_model_stdm, color="tab:red", alpha=0.3, ) # plot CCMP2 WSP ax.plot(time, wsp_mean, ".-r", linewidth=linewidth) ax.plot(time, wsp_mean, ".r", markersize=2) ax.fill_between(time, wsp_mean - wsp_stdm, wsp_mean + wsp_stdm, color="red", alpha=0.3) # Ifremer-CCMP2 comparison and residual elif task == "C_I_res": # plot CCMP2 WSP ax.plot(time, wsp_mean, ".-r", linewidth=linewidth) ax.plot(time, wsp_mean, ".r", markersize=2) ax.fill_between(time, wsp_mean - wsp_stdm, wsp_mean + wsp_stdm, color=color, alpha=0.3) # Ifremer-CCMP2 comparison else: # plot CCMP2 WSP ax.plot(time, wsp_mean, ".-r", linewidth=linewidth) ax.plot(time, wsp_mean, ".r", markersize=2) ax.plot(time, wsp_hfit, ".--r", linewidth=linewidth) ax.plot(time, wsp_hfit, ".r", markersize=2) ax.fill_between(time, wsp_mean - wsp_stdm, wsp_mean + wsp_stdm, color=color, alpha=0.3) # set WSP y-axis attributes: if task == "C_I_res": ax.set_ylabel("$m\,s^{-1}$", color=color, fontsize=fontsize) ax.set_yticks(np.arange(ylim[1][0], ylim[1][1] + 0.5, 0.5)) for label in ax.yaxis.get_ticklabels()[1::2]: label.set_visible(False) else: ax.set_ylabel("$WSP\;(m\,s^{-1})$", color=color, fontsize=fontsize) ax.set_ylim(ylim[1]) ax.tick_params(axis="y", labelsize=fontsize) # set grid lines if grid == True: ax.grid(color=color, linestyle="-.", linewidth=1, alpha=0.35) # set attributes of rest of subplot: ax.set_xlim([0, 13]) ax.set_xticklabels(time_ticks, fontsize=fontsize) ax.tick_params(axis="x", labelsize=fontsize) # hind every other ticklabel start, end = ax.get_xlim() ax.xaxis.set_ticks(np.arange(start + 1, end + 1, 1)) for label in ax.xaxis.get_ticklabels()[::2]: label.set_visible(False) # set labels on figure cart.subplot_label( ax, xdist_label=0.08, ydist_label=0.92, subplot_label=subplot_label, form="box", fs_shade=28, fs_main=20, color="black", )
height=4, edgecolor="black", facecolor=None, linestyle="-", linewidth=2, fill=False, alpha=1, transform=ccrs.PlateCarree(), )) # Plot labels for grid boxes cart.subplot_label( axes, xdist_label=0.515, ydist_label=0.71, subplot_label="S6A", form="box", fs_shade=28, fs_main=18, color="tab:blue", ) cart.subplot_label( axes, xdist_label=0.69, ydist_label=0.57, subplot_label="S6B", form="box", fs_shade=28, fs_main=18, color="tab:blue", ) cart.subplot_label(
cs1, cax1, fig, orientation="vertical", extend="both", cbar_label="$m$", nbins=9, fontsize=12, cbar_ticks=[], task="regular", ) cart.subplot_label( ax1, xdist_label=0.1, ydist_label=0.86, subplot_label="A", form="box", fs_shade=28, fs_main=18, color="black", ) cart.subplot_label( ax1, xdist_label=0.22, ydist_label=0.86, subplot_label="DJF", form="box", fs_shade=28, fs_main=18, color="black", )