Example #1
0
def test_violinplot_beanplot():
    # Test violinplot and beanplot with the same dataset.
    data = anes96.load_pandas()
    party_ID = np.arange(7)
    labels = ["Strong Democrat", "Weak Democrat", "Independent-Democrat",
              "Independent-Independent", "Independent-Republican",
              "Weak Republican", "Strong Republican"]

    age = [data.exog['age'][data.endog == id] for id in party_ID]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    violinplot(age, ax=ax, labels=labels,
               plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
                          'label_fontsize':'small',
                          'label_rotation':30})

    plt.close(fig)


    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels,
             plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
                        'label_fontsize':'small',
                        'label_rotation':30})

    plt.close(fig)
Example #2
0
def test_violinplot_beanplot(close_figures):
    # Test violinplot and beanplot with the same dataset.
    data = anes96.load_pandas()
    party_ID = np.arange(7)
    labels = ["Strong Democrat", "Weak Democrat", "Independent-Democrat",
              "Independent-Independent", "Independent-Republican",
              "Weak Republican", "Strong Republican"]

    age = [data.exog['age'][data.endog == id] for id in party_ID]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    violinplot(age, ax=ax, labels=labels,
               plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
                          'label_fontsize':'small',
                          'label_rotation':30})

    fig = plt.figure()
    ax = fig.add_subplot(111)
    violinplot(age, ax=ax, labels=labels,
               plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
                          'label_fontsize':'small',
                          'label_rotation':30,
                          'bw_factor':.2})

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels,
             plot_opts={'cutoff_val':5, 'cutoff_type':'abs',
                        'label_fontsize':'small',
                        'label_rotation':30})

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels, jitter=True,
             plot_opts={'cutoff_val': 5, 'cutoff_type': 'abs',
                        'label_fontsize': 'small',
                        'label_rotation': 30})

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels, jitter=True, side='right',
             plot_opts={'cutoff_val': 5, 'cutoff_type': 'abs',
                        'label_fontsize': 'small',
                        'label_rotation': 30})

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels, jitter=True, side='left',
             plot_opts={'cutoff_val': 5, 'cutoff_type': 'abs',
                        'label_fontsize': 'small',
                        'label_rotation': 30})

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels,
             plot_opts={'bean_legend_text': 'text'})
Example #3
0
def test_violinplot(age_and_labels, close_figures):
    age, labels = age_and_labels

    fig, ax = plt.subplots(1, 1)
    violinplot(age,
               ax=ax,
               labels=labels,
               plot_opts={
                   'cutoff_val': 5,
                   'cutoff_type': 'abs',
                   'label_fontsize': 'small',
                   'label_rotation': 30
               })
Example #4
0
def test_violinplot_beanplot():
    """Test violinplot and beanplot with the same dataset."""
    data = anes96.load_pandas()
    party_ID = np.arange(7)
    labels = [
        "Strong Democrat", "Weak Democrat", "Independent-Democrat",
        "Independent-Independent", "Independent-Republican", "Weak Republican",
        "Strong Republican"
    ]

    age = [data.exog['age'][data.endog == id] for id in party_ID]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    violinplot(age,
               ax=ax,
               labels=labels,
               plot_opts={
                   'cutoff_val': 5,
                   'cutoff_type': 'abs',
                   'label_fontsize': 'small',
                   'label_rotation': 30
               })

    plt.close(fig)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age,
             ax=ax,
             labels=labels,
             plot_opts={
                 'cutoff_val': 5,
                 'cutoff_type': 'abs',
                 'label_fontsize': 'small',
                 'label_rotation': 30
             })

    plt.close(fig)
    diff_satids = []
    for ss in range(len(satlab)):
        diff_satid = []
        for ii in range(len(sat_imerg[ss])):
            if sat_imerg[ss][ii] >= minrain or sat_pcmk[ss][ii] >= minrain:
                diff_satid.append(sat_anom[ss][ii])
                if ss == 5 and sat_anom[ss][ii] < -50:
                    pcmk_ssmis_min = sat_pcmk[ss][ii]  # PCMK for that event
        diff_satids.append(diff_satid)

    print('PCMK: %5.1f' % pcmk_ssmis_min)

    plt.figure(figsize = (scol, 0.75 * scol))

    violinplot(diff_satids, ax = plt.gca(), positions = range(len(sat_anom)), 
               show_boxplot = False,  plot_opts = {'violin_fc': '0.2', 
               'violin_ec': 'k', 'cutoff': True})

    bp = plt.boxplot(diff_satids, positions = range(len(sat_anom)), 
                whis = [10, 90])
    for flier in bp['fliers']:
        flier.set(marker = 'x', mec = 'k', ms = 4, alpha = 1)
    plt.ylim([-54, 32])

    circle = Ellipse((5, min(diff_satids[5])), 0.5, 6.3, color = 'r', 
                     fill = False)
    plt.gca().add_artist(circle)

    plt.xticks(range(len(diff_satids)), satlab, rotation = 'vertical')
    plt.setp(plt.gca(), 'xticklabels', satlab)
    plt.ylabel('%s − %s (mm / h)' % (datalab['imerg'], datalab['pcmk']))
Example #6
0
def test_violinplot_beanplot(close_figures):
    # Test violinplot and beanplot with the same dataset.
    data = anes96.load_pandas()
    party_ID = np.arange(7)
    labels = [
        "Strong Democrat", "Weak Democrat", "Independent-Democrat",
        "Independent-Independent", "Independent-Republican", "Weak Republican",
        "Strong Republican"
    ]

    age = [data.exog['age'][data.endog == id] for id in party_ID]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    violinplot(age,
               ax=ax,
               labels=labels,
               plot_opts={
                   'cutoff_val': 5,
                   'cutoff_type': 'abs',
                   'label_fontsize': 'small',
                   'label_rotation': 30
               })

    fig = plt.figure()
    ax = fig.add_subplot(111)
    violinplot(age,
               ax=ax,
               labels=labels,
               plot_opts={
                   'cutoff_val': 5,
                   'cutoff_type': 'abs',
                   'label_fontsize': 'small',
                   'label_rotation': 30,
                   'bw_factor': .2
               })

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age,
             ax=ax,
             labels=labels,
             plot_opts={
                 'cutoff_val': 5,
                 'cutoff_type': 'abs',
                 'label_fontsize': 'small',
                 'label_rotation': 30
             })

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age,
             ax=ax,
             labels=labels,
             jitter=True,
             plot_opts={
                 'cutoff_val': 5,
                 'cutoff_type': 'abs',
                 'label_fontsize': 'small',
                 'label_rotation': 30
             })

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age,
             ax=ax,
             labels=labels,
             jitter=True,
             side='right',
             plot_opts={
                 'cutoff_val': 5,
                 'cutoff_type': 'abs',
                 'label_fontsize': 'small',
                 'label_rotation': 30
             })

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age,
             ax=ax,
             labels=labels,
             jitter=True,
             side='left',
             plot_opts={
                 'cutoff_val': 5,
                 'cutoff_type': 'abs',
                 'label_fontsize': 'small',
                 'label_rotation': 30
             })

    fig = plt.figure()
    ax = fig.add_subplot(111)
    beanplot(age, ax=ax, labels=labels, plot_opts={'bean_legend_text': 'text'})
Example #7
0
                P[rr, tt] = np.ma.mean([ii for ii in precip[t0 : t1][R[t0 : t1] == rr + 1]])
                F[rr, tt] = np.ma.sum(R[t0 : t1] == rr + 1) / np.float(np.ma.count(R[t0 : t1]))
                Pall[rr] += [ii for ii in precip[t0 : t1][R[t0 : t1] == rr + 1] if not np.ma.is_masked(ii)]
            P[nreg, tt] = np.ma.mean([ii for ii in precip[t0 : t1][R[t0 : t1] < 4]])
            F[nreg, tt] = np.ma.sum(R[t0 : t1] < 4) / np.float(np.ma.count(R[t0 : t1]))
            Pall[nreg] += [ii for ii in precip[t0 : t1][R[t0 : t1] < 4] if not np.ma.is_masked(ii)]

            t0 = t1
            tt += 1

    Pcon = [np.sum(Pall[rr]) / Ptotal for rr in range(nreg + 1)]    # fractional contribution

    x = np.arange(nreg + 1)

    plt.figure(figsize = (scol, 0.5 * scol))
    violinplot(Pall, ax = plt.gca(), positions = x, show_boxplot = False,
        plot_opts = {'violin_fc': '0.2', 'violin_ec': 'k', 'cutoff': True})
    bp = plt.boxplot(Pall, sym = '', widths = 0.4, positions = x, whis = [5, 95])
    plt.setp(bp['boxes'], color = 'black')
    plt.setp(bp['whiskers'], color = 'black', linestyle = '-')
    plt.setp(bp['medians'], color = 'black')
    plt.scatter(x, [np.mean(ii) for ii in Pall], s = 10, c = 'k')
    for rr in range(nreg + 1): plt.text(x[rr], 105, '{:2.0f}%'.format(Pcon[rr] * 100), ha = 'center')
    plt.ylim([0, 100])
    plt.setp(plt.gca(), 'xticks', x)
    plt.setp(plt.gca(), 'xticklabels', regimes + ('CR1-3',))
    plt.ylabel('$P$ (mm / day)')
    plt.grid(axis = 'y')
    plt.axvline(2.5, c = 'k', ls = ':', lw = 0.5)
    plt.savefig('Fig2.pdf')
    plt.close()
        for ii in range(len(sat_imerg[ss])):
            if sat_imerg[ss][ii] >= minrain or sat_pcmk[ss][ii] >= minrain:
                diff_satid.append(sat_anom[ss][ii])
                if ss == 5 and sat_anom[ss][ii] < -50:
                    pcmk_ssmis_min = sat_pcmk[ss][ii]  # PCMK for that event
        diff_satids.append(diff_satid)

    print('PCMK: %5.1f' % pcmk_ssmis_min)

    plt.figure(figsize=(scol, 0.75 * scol))

    violinplot(diff_satids,
               ax=plt.gca(),
               positions=range(len(sat_anom)),
               show_boxplot=False,
               plot_opts={
                   'violin_fc': '0.2',
                   'violin_ec': 'k',
                   'cutoff': True
               })

    bp = plt.boxplot(diff_satids,
                     positions=range(len(sat_anom)),
                     whis=[10, 90])
    for flier in bp['fliers']:
        flier.set(marker='x', mec='k', ms=4, alpha=1)
    plt.ylim([-54, 32])

    circle = Ellipse((5, min(diff_satids[5])), 0.5, 6.3, color='r', fill=False)
    plt.gca().add_artist(circle)
Example #9
0
    use = R2[full_model] > .5

    import statsmodels.graphics.boxplots as sgb
    import matplotlib.patches as mpatches

    fig = plt.figure(figsize=(12, 6))
    fig.clf()

    for j, tmod in enumerate([tested_models1, tested_models2]):
        ax = fig.add_axes([.12, .65 - .45 * j, .8, .3])
        for i, mod in enumerate(true_models):
            for k, m in enumerate(tmod):
                color = 'rgbcymk'[k]
                vals = (R2[full_model] - R2[m])[use & (tgc == mod)].dropna()
                if len(vals) > 3:
                    sgb.violinplot([vals],ax=ax,positions=[i+.2*k],show_boxplot=False,\
                                   plot_opts=dict(violin_fc=color,violin_ec=color,violin_alpha=.5,violin_width=.15,cutoff=True))
                bp = ax.boxplot([vals],
                                positions=[i + .2 * k],
                                widths=.1,
                                sym='',
                                notch=False)
                plt.setp(bp['boxes'], color='k', linewidth=1)
                plt.setp(bp['whiskers'],
                         color='k',
                         linestyle='solid',
                         linewidth=.5)
                plt.setp(bp['caps'], color='k')
                plt.setp(bp['medians'], color='r')
        patches = [
            mpatches.Patch(color='rgbcymk'[k], alpha=.5)
            for k in range(len(tmod))