Beispiel #1
0
def plot_mfc_budget(mfc_budget, index, year, legend=True,
                    legend_kw={'fontsize' : 9, 'loc' : 'upper left',
                               'handlelength' : 2.5},
                    dashes=[6, 2], netprecip=False):
    ts = mfc_budget.sel(year=year)
    ind = index.sel(year=year)
    days = ts['day'].values
    styles = {'PRECTOT' : {'color' : 'k', 'linestyle' : '--', 'dashes' : dashes},
              'EVAP' : {'color' : 'k'},
              'MFC' : {'color' : 'k', 'linewidth' : 2},
              'dw/dt' : {'color' : '0.7', 'linewidth' : 2}}
    if netprecip:
        styles['P-E'] = {'color' : 'b', 'linewidth' : 2}
    for nm in styles:
        plt.plot(days, ts[nm], label=nm, **styles[nm])
    plt.axvline(ind['onset'], color='k')
    plt.axvline(ind['retreat'], color='k')
    plt.xlabel('Day of Year')
    plt.ylabel('mm/day')
    ax1 = plt.gca()
    ax2 = plt.twinx()
    plt.sca(ax2)
    plt.plot(days, ind['tseries'], 'r', alpha=0.6, linewidth=2, label='CMFC')
    atm.fmt_axlabels('y', 'mm', color='r', alpha=0.6)
    if legend:
        atm.legend_2ax(ax1, ax2, **legend_kw)
    return ax1, ax2
Beispiel #2
0
def plotyy(data1, data2=None, xname='dayrel', data1_styles=None,
           y2_opts={'color' : 'r', 'alpha' : 0.6, 'linewidth' : 2},
           xlims=None, xticks=None, ylims=None, yticks=None, y2_lims=None,
           xlabel='', y1_label='', y2_label='', legend=False,
           legend_kw={'fontsize' : 9, 'handlelength' : 2.5},
           x0_axvlines=None, grid=True):
    """Plot data1 and data2 together on different y-axes."""

    data1, data2 = atm.to_dataset(data1), atm.to_dataset(data2)

    for nm in data1.data_vars:
        if data1_styles is None:
            plt.plot(data1[xname], data1[nm], label=nm)
        elif isinstance(data1_styles[nm], dict):
            plt.plot(data1[xname], data1[nm], label=nm, **data1_styles[nm])
        else:
            plt.plot(data1[xname], data1[nm], data1_styles[nm], label=nm)
    atm.ax_lims_ticks(xlims, xticks, ylims, yticks)
    plt.grid(grid)
    if x0_axvlines is not None:
        for x0 in x0_axvlines:
            plt.axvline(x0, color='k')
    plt.xlabel(xlabel)
    plt.ylabel(y1_label)
    axes = [plt.gca()]

    if data2 is not None:
        plt.sca(plt.gca().twinx())
        for nm in data2.data_vars:
            plt.plot(data2[xname], data2[nm], label=nm, **y2_opts)
        if y2_lims is not None:
            plt.ylim(y2_lims)
        if 'linewidth' in y2_opts:
            y2_opts.pop('linewidth')
        atm.fmt_axlabels('y', y2_label, **y2_opts)
        atm.ax_lims_ticks(xlims, xticks)
    axes = axes + [plt.gca()]

    if legend:
        if data2 is None:
            plt.legend(**legend_kw)
        else:
            atm.legend_2ax(axes[0], axes[1], **legend_kw)

    return axes
def lineplots(data1, data2=None, data1_style=None, xlims=None, xticks=None,
              ylims=None, yticks=None, length=None, legend=False,
              legend_kw={'fontsize' : 9, 'handlelength' : 2.5},
              y2_lims=None, y2_opts={'color' : 'r', 'alpha' : 0.6},
              y1_label='', y2_label='', grp=None):

    data1, data2 = to_dataset(data1), to_dataset(data2)

    for nm in data1.data_vars:
        if data1_style is None:
            plt.plot(data1['dayrel'], data1[nm], label=nm)
        else:
            plt.plot(data1['dayrel'], data1[nm], data1_style[nm], label=nm)
    fmt_axes(xlims, xticks, ylims, yticks)
    plt.grid(True)
    plt.axvline(0, color='k')
    if length is not None:
        plt.axvline(length, color='k')
    if grp is not None and grp.row == grp.ncol - 1:
        plt.xlabel('Rel Day')
    plt.ylabel(y1_label)
    axes = [plt.gca()]

    if data2 is not None:
        plt.sca(plt.gca().twinx())
        for nm in data2.data_vars:
            plt.plot(data2['dayrel'], data2[nm], label=nm, linewidth=2,
                     **y2_opts)
        if y2_lims is not None:
            plt.ylim(y2_lims)
        atm.fmt_axlabels('y', y2_label, **y2_opts)
    axes = axes + [plt.gca()]

    if legend:
        if data2 is None:
            plt.legend(**legend_kw)
        else:
            atm.legend_2ax(axes[0], axes[1], **legend_kw)

    return axes