コード例 #1
0
def plot_double_ecoregions_map(extent, mega1, la_lo_ext_small):
    s = splot(1,
              2,
              figsize=(7.25, 3.5),
              subplot_kw={'projection': crt.crs.PlateCarree()},
              dpi=300)
    ext_zoom = get_extent(la_lo_ext_small, la_lo_ext_small)
    plot_ecoregion(
        s.axf[0],
        extent,
        mega1,
        # p1=ext_zoom[1], p2=ext_zoom[3],
        edgecolor='r',
        right_lab=False,
        left_lab=True)
    s.axf[0].set_ylabel(r'latitude [$\degree$]')
    s.axf[0].set_xlabel(r'longitude [$\degree$]')
    ax_zoom = s.axf[1]
    plot_ecoregion(ax_zoom,
                   ext_zoom,
                   mega1,
                   xticks=[-70, -68, -66],
                   yticks=[-16, -18],
                   xd=+.03,
                   right_lab=True,
                   left_lab=False)
    decorate_zoom_ax(ax_zoom)

    fa.add_ax_lab(s.ax[0], 'a')
    fa.add_ax_lab(s.ax[1], 'b')
    return s
コード例 #2
0
    def __init__(self, combined_gdf: geopandas.GeoDataFrame, topoline, gdf18):
        self.combined_gdf = combined_gdf
        self.topoline = topoline
        self.gdf18 = gdf18

        self.size_x = 7.25
        self.size_y = self.size_x
        self.f: plt.Figure = plt.figure(figsize=(self.size_x, self.size_y),
                                        dpi=300)

        h_ratios = [2, 2, .6]
        self.grid = self.f.add_gridspec(3, 2, height_ratios=h_ratios)

        self.proj = crt.crs.PlateCarree()
        self.axA = self.f.add_subplot(self.grid[0, 0], projection=self.proj)
        self.axB = self.f.add_subplot(self.grid[0, 1], projection=self.proj)
        self.axC = self.f.add_subplot(self.grid[1, 0], projection=self.proj)
        self.axD = self.f.add_subplot(self.grid[1, 1], projection=self.proj)
        self.axE = self.f.add_subplot(self.grid[2, :])

        self.xlab = r'longitude [$\degree$]'
        self.ylab = r'latitude [$\degree$]'

        self.big_xticks = [-80, -70, -60]
        self.big_yticks = [-10, -20, -30]
        self.small_xticks = [-69, -67]
        self.small_yticks = [-16, -18]

        self.la_lo_ext_big = 15
        self.la_lo_ext_small = 2.2
        self.ext_small = get_extent(self.la_lo_ext_small, self.la_lo_ext_small)
        self.ext_big = get_extent(self.la_lo_ext_big, self.la_lo_ext_big)

        self.plot_axA()
        self.plot_axB()
        self.plot_axC()
        self.plot_axD()
        self.plot_axE()

        fa.add_ax_lab(self.axA, 'a')
        fa.add_ax_lab(self.axB, 'b')
        fa.add_ax_lab(self.axC, 'c')
        fa.add_ax_lab(self.axD, 'd')

        self.f.subplots_adjust(left=.1,
                               right=.9,
                               bottom=.0,
                               top=.95,
                               hspace=.1,
                               wspace=.005)
コード例 #3
0
def add_indices(ax1, ax2, ax3, ax4):
    axs = [ax1, ax2, ax3, ax4]
    texts = ['a', 'b', 'c', 'd']
    for ax, text in zip(axs, texts):
        fa.add_ax_lab(ax, text)
コード例 #4
0
def plot_ts_clus(
    dds,
    km,
    cl_lab,
    _in,
    h0=0,
    h1=24,
):
    nc = km.n_clusters
    rx = 2
    ry = int(np.ceil(nc / rx))
    s = splot(rx,
              ry,
              sharey=False,
              sharex=False,
              dpi=300,
              figsize=(3.14, 3),
              squeeze=False)
    # for i, ax in enumerate(s.axf):

    # _std = dds.to_dataframe().groupby('labs').mean()[
    #     'conc_lab_nc18'].sort_values()
    # print(_std)
    # index_ = _std.index.values
    # print(index_)

    for i, ci in enumerate(_in):
        ax = s.axf[i]
        sel = dds[{'date': dds['labs'] == ci}] * 100
        tot = len(dds['date'])
        yM = dds.quantile(.999) * 100
        ym = dds.quantile(.001) * 100
        yy = np.max([yM, -ym])
        sel.plot(
            hue='date',
            add_legend=False,
            # col='labs',
            # col_wrap=4
            ax=ax,
            color='k',
            alpha=.1,
            xlim=[h0, h1],
            ylim=[-yy, yy],
            linewidth=.7)
        cen = km.cluster_centers_[ci] * 100
        _df = pd.Series(cen[:, 0], index=dds['hour'].values)
        _df.plot(ax=ax, c=ucp.cc[0])
        ax.set_title(f'n={len(sel)} ({len(sel)/tot*100:2.0f}%)',
                     loc='right',
                     y=.95,
                     alpha=.5,
                     size=8)
        # ax.set_ylabel('SRR [%]')
        ax.set_ylabel(None)
        ax.set_xlabel(None)
        ax.set_xticks(np.arange(h0, h1 + 1, 4))
        ax.set_xticks(np.arange(h0, h1 + 1, 2), minor=True)
        # ax.set_yticks([0,5,10,15])
        ax.axvline(12, c=ucp.cc[2], zorder=0, alpha=.5, linestyle='--')
        sns.despine(ax=ax, trim=True, offset=[0, 5])
    if ry > 1:
        for ax in s.axs[:, 1:].flatten():
            # sns.despine(ax=ax,left=True)
            ax.spines['left'].set_visible(False)
            ax.set_yticks([])
            ax.set_yticks([], minor=True)
            ax.set_ylabel(None)
    if rx > 1:
        for ax in s.axs[:-1, :].flatten():
            ax.spines['bottom'].set_visible(False)
            ax.set_xticks([])
            ax.set_xticks([], minor=True)
            ax.set_xlabel(None)
    s.axs[-1, 0].set_xlabel('Local time [hour]')
    s.axs[-1, 0].set_ylabel('det. SRR [%]')
    s.f.tight_layout()
    s.f.suptitle(f'{cl_lab}', va='top')
    fa.add_ax_lab(s.axf[0], 'a')
    fa.add_ax_lab(s.axf[1], 'b')
    # s.f.subplots_adjust(top=.9)
    s.f.tight_layout()
    plt.show()
    return s
コード例 #5
0
def create_combined_plot_simple(conc_name,
                                dac_sum,
                                npdf,
                                path_colors,
                                *,
                                out_name,
                                background_alpha=0,
                                f_width=7.25,
                                min_fs=8,
                                med_fs=10,
                                add_patch=False):

    f_width = f_width
    figsize = (f_width, f_width / 1.7)
    # figsize = (f_width, f_width / .6)
    f, axs = plt.subplots(1,
                          2,
                          subplot_kw=dict(projection=crt.crs.PlateCarree()),
                          figsize=figsize,
                          dpi=300)
    axl = axs.flatten()

    f: plt.Figure
    lon_range = 2.2
    lat_range = 2.2
    axBO = plot_pathways(npdf,
                         dac_sum,
                         conc_name,
                         ax=axl[0],
                         centroid_to_plot=['MR', 'SM', 'SR', 'LR'],
                         labs_to_plot=['MR', 'LR'],
                         lon_range=15,
                         lat_range=15,
                         min_fs=min_fs,
                         add_patch=add_patch,
                         background_alpha=background_alpha)

    plot_altiplano_line(axBO, min_fs)

    import matplotlib.patches as patches
    cc = get_extent(lon_range, lat_range)
    rect = patches.Rectangle([cc[1], cc[3]],
                             2 * lon_range,
                             2 * lat_range,
                             zorder=10,
                             facecolor='none',
                             edgecolor='r',
                             linestyle='-.',
                             linewidth=1.5)
    axBO.add_patch(rect)
    axLP = plot_pathways(npdf,
                         dac_sum,
                         conc_name,
                         lon_range=lon_range,
                         lat_range=lat_range,
                         centroid_to_plot=['MR', 'SM', 'SR'],
                         chc_lp_legend=False,
                         q_level=.9,
                         ax_bolivia=False,
                         ax=axl[1],
                         min_fs=min_fs,
                         add_patch=False,
                         background_alpha=background_alpha)

    plot_altiplano_line(axLP, min_fs, annotate=False)
    # axLP.plot(*seg, **alt_style)

    axLP.outline_patch.set_edgecolor('red')
    axLP.outline_patch.set_linewidth(2)
    axLP.outline_patch.set_linestyle('-.')
    axLP.annotate(
        'CHC',
        xy=[co.CHC_LON - .05, co.CHC_LAT],
        xytext=[20, 0],
        textcoords='offset points',
        zorder=30,
        # alpha = .5,
        fontsize=min_fs,
        arrowprops=dict(arrowstyle='->', alpha=1))
    axLP.annotate(
        'LPB',
        xy=[co.LPB_LON, co.LPB_LAT],
        xytext=[-10, -20],
        textcoords='offset points',
        zorder=30,
        # alpha = .5,
        fontsize=min_fs,
        arrowprops=dict(arrowstyle='->', alpha=1))
    axLP.set_xticks([-70, -68, -66], crs=crt.crs.PlateCarree())
    axLP.set_yticks([-16, -18], crs=crt.crs.PlateCarree())
    axLP.yaxis.set_ticks_position('right')
    axBO.set_xticks([-80, -70, -60], crs=crt.crs.PlateCarree())
    axBO.set_yticks([-10, -20, -30], crs=crt.crs.PlateCarree())
    axBO.set_ylabel(r'latitude [$\degree$]')
    axBO.set_xlabel(r'longitude [$\degree$]')
    axLP.annotate('zoomed in panel',
                  xy=[1, 1],
                  xytext=[0, 2],
                  xycoords='axes fraction',
                  textcoords='offset points',
                  verticalalignment='bottom',
                  horizontalalignment='right',
                  zorder=30,
                  fontsize=min_fs,
                  color='red')

    if add_patch:

        add_pathways_lab(axBO, axLP, min_fs, path_colors, bbox_props)

    fa.add_ax_lab(axBO, 'a)')
    fa.add_ax_lab(axLP, 'b)')
    f.subplots_adjust(wspace=.05,
                      hspace=.13,
                      top=.97,
                      bottom=.07,
                      left=0.09,
                      right=.93)
    axLP.figure.show()
    axBO.figure.savefig(pjoin(co.paper_fig_path, out_name))
コード例 #6
0
def create_combined_plot(conc_name,
                         dac_sum,
                         npdf,
                         path_colors,
                         *,
                         out_name,
                         f_width=7.25,
                         min_fs=8,
                         med_fs=10):
    seg = get_topoline(zline=3900)
    # %%
    ucp.set_dpi(300)
    f_width = f_width
    figsize = (f_width, f_width / 1.7)
    # figsize = (f_width, f_width / .6)
    f, axs = plt.subplots(1,
                          2,
                          subplot_kw=dict(projection=crt.crs.PlateCarree()),
                          figsize=figsize)
    f: plt.Figure
    lon_range = 2.2
    lat_range = 2.2
    axl = axs.flatten()
    axBO = plot_pathways(npdf,
                         dac_sum,
                         conc_name,
                         ax=axl[0],
                         lon_range=15,
                         lat_range=15,
                         min_fs=min_fs)
    axBO.plot(
        *seg,
        transform=crt.crs.PlateCarree(),
        c='k',
        linestyle='--',
    )
    ll = pd.DataFrame(seg.T, columns=['lo', 'la']).sort_values('la').iloc[-1]
    bbox_props = dict(boxstyle="round", fc="w", ec="none", alpha=0.5)
    axBO.annotate(
        '$z=3.9$ km',
        ll.values,
        xytext=[-30, 20],
        textcoords='offset points',
        zorder=12,
        alpha=.5,
        fontsize=min_fs,
        arrowprops=dict(arrowstyle='->', alpha=.5),
        bbox=bbox_props,
    )

    import matplotlib.patches as patches
    cc = get_extent(lon_range, lat_range)
    rect = patches.Rectangle([cc[1], cc[3]],
                             2 * lon_range,
                             2 * lat_range,
                             zorder=10,
                             facecolor='none',
                             edgecolor='r',
                             linestyle='-.',
                             linewidth=1.5)
    axBO.add_patch(rect)
    # axBO.figure.show()
    axLP = plot_pathways(npdf,
                         dac_sum,
                         conc_name,
                         lon_range=lon_range,
                         lat_range=lat_range,
                         centroid_to_plot=['MR', 'SM', 'SR'],
                         chc_lp_legend=False,
                         q_level=.9,
                         ax_bolivia=False,
                         ax=axl[1],
                         min_fs=min_fs)
    axLP.plot(*seg, transform=crt.crs.PlateCarree(), c='k', linestyle='--')
    axLP.outline_patch.set_edgecolor('red')
    axLP.outline_patch.set_linewidth(2)
    axLP.outline_patch.set_linestyle('-.')
    axLP.annotate(
        'CHC',
        xy=[co.CHC_LON - .05, co.CHC_LAT],
        xytext=[20, 0],
        textcoords='offset points',
        zorder=30,
        # alpha = .5,
        fontsize=min_fs,
        arrowprops=dict(arrowstyle='->', alpha=1))
    axLP.annotate(
        'LPB',
        xy=[co.LPB_LON, co.LPB_LAT],
        xytext=[-10, -20],
        textcoords='offset points',
        zorder=30,
        # alpha = .5,
        fontsize=min_fs,
        arrowprops=dict(arrowstyle='->', alpha=1))
    axLP.set_xticks([-70, -68, -66], crs=crt.crs.PlateCarree())
    axLP.set_yticks([-16, -18], crs=crt.crs.PlateCarree())
    axLP.yaxis.set_ticks_position('right')
    axBO.set_xticks([-80, -70, -60], crs=crt.crs.PlateCarree())
    axBO.set_yticks([-10, -20, -30], crs=crt.crs.PlateCarree())
    axBO.set_ylabel(r'latitude [$\degree$]')
    axBO.set_xlabel(r'longitude [$\degree$]')
    axLP.annotate('zoomed in panel',
                  xy=[1, 1],
                  xytext=[0, 2],
                  xycoords='axes fraction',
                  textcoords='offset points',
                  verticalalignment='bottom',
                  horizontalalignment='right',
                  zorder=30,
                  fontsize=min_fs,
                  color='red')

    add_pathways_lab(axBO, axLP, min_fs, path_colors, bbox_props)

    fa.add_ax_lab(axBO, 'a)')
    fa.add_ax_lab(axLP, 'b)')
    f.subplots_adjust(wspace=.05,
                      hspace=.13,
                      top=.97,
                      bottom=.07,
                      left=0.09,
                      right=.93)
    axLP.figure.show()
    axBO.figure.savefig(pjoin(co.paper_fig_path, out_name))