Exemple #1
0
def twinhist(X, Y, ax=None, xbins=10, ybins=10, fmt='o',
             color='b', histalpha=0.5, xlabel=None, ylabel=None,
             xlim=None, ylim=None, **kwargs):
    """ Plot a twin histogram."""

    from barak.plot import hist_xedge, hist_yedge
    if ax is None:
        ax = pl.gca()
    
    ax.plot(X,Y, fmt, color=color, **kwargs)
    hist_xedge(X,ax, bins=xbins,fill=True, color=color, alpha=histalpha)
    hist_yedge(Y,ax, bins=ybins,fill=True, color=color, alpha=histalpha)
    if xlim is not None:
        ax.set_xlim(*xlim)
    if ylim is not None:
        ax.set_ylim(*ylim)
    if xlabel is not None:
        ax.set_xlabel(xlabel)
    if ylabel is not None:
        ax.set_ylabel(ylabel)
    return ax
Exemple #2
0
def plot_posteriors(chain, P, nplot='all'):
    """ Plot the posterior distributions for a series of parameter
    samples. chain has shape (nsample, nparameters).
    """

    if nplot == 'all':
        nplot = chain.shape[-1]

    #nrows, ncols = get_nrows_ncols(nplot)
    #fig,axes = get_fig_axes(nrows, ncols, nplot)

    fig = pl.figure(figsize=(8.4, 8.4))
    fig.subplots_adjust(left=0.05, bottom=0.05, hspace=0.001, wspace=0.001)
    axes = []
    pl.rc('xtick', labelsize=8)
    pl.rc('ytick', labelsize=8)

    for i0 in xrange(nplot):
        for i1 in xrange(nplot):
            if i0 == i1:# or i1 < i0:
                continue
            ax = fig.add_subplot(nplot,nplot, i0 * nplot + i1 + 1)

            y,x = chain[:,i0], chain[:,i1]
            ax.plot(x,y,'r.', ms=1, mew=0)#, alpha=0.5)
            #y,x = chain[:,i0][P['ijoint_sig'][1]], chain[:,i1][P['ijoint_sig'][1]]
            #ax.plot(x,y,'g.', ms=1.5, mew=0)
            #y,x = chain[:,i0][P['ijoint_sig'][0]], chain[:,i1][P['ijoint_sig'][0]]
            #ax.plot(x,y,'r.', ms=1.5, mew=0)

            ax.plot(P['ml'][i1], P['ml'][i0], 'xk', ms=8, mew=2)
            ax.plot(P['ml'][i1], P['ml'][i0], 'xr', ms=6, mew=1)


            puttext(0.05, 0.95, P['names'][i0], ax, fontsize=12, va='top')
            puttext(0.95, 0.05, P['names'][i1], ax, fontsize=12, ha='right')
            y0, y1 = np.percentile(chain[:,i0], [5, 95])
            dy = y1 - y0
            ax.set_ylim(y0 - dy, y1 + dy)
            x0, x1 = np.percentile(chain[:,i1], [5, 95])
            dx = x1 - x0
            ax.set_xlim(x0 - dx, x1 + dx)

            c = 'crimson'
            if i0 == 0:
                ax.xaxis.set_tick_params(labeltop='on')
                ax.xaxis.set_tick_params(labelbottom='off')
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            elif i0 == nplot-1 or (i0 == nplot-2 and i1 == nplot-1):
                hist_xedge(chain[:, i1], ax, fmt='b', bins=P['bins'][i1], loc='bottom')
                ax.axvline(P['p1sig'][i1][0], ymax=0.2, color=c, lw=0.5)
                ax.axvline(P['p1sig'][i1][1], ymax=0.2, color=c, lw=0.5)
                ax.axvline(P['median'][i1], ymax=0.2, color=c, lw=1.5)
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            else:
                ax.set_xticklabels('')

            if not (i1 == 0 or (i0 == 0 and i1 == 1) or i1 == nplot-1):
                ax.set_yticklabels('')

            if (i0 == 0 and i1 == 1) or i1 == 0:
                hist_yedge(chain[:, i0], ax, fmt='b', bins=P['bins'][i0], loc='left')
                ax.axhline(P['p1sig'][i0][0], xmax=0.2, color=c, lw=0.5)
                ax.axhline(P['p1sig'][i0][1], xmax=0.2, color=c, lw=0.5)
                ax.axhline(P['median'][i0], xmax=0.2, color=c, lw=1.5)


            if i1 == nplot - 1:
                ax.yaxis.set_tick_params(labelright='on')
                ax.yaxis.set_tick_params(labelleft='off')
                
            axes.append(ax)

    return fig, axes
Exemple #3
0
def plot_posteriors(chain, P, nplot="all"):
    """ Plot the posterior distributions for a series of parameter
    samples. chain has shape (nsample, nparameters).
    """

    if nplot == "all":
        nplot = chain.shape[-1]

    # nrows, ncols = get_nrows_ncols(nplot)
    # fig,axes = get_fig_axes(nrows, ncols, nplot)

    fig = pl.figure(figsize=(8.4, 8.4))
    fig.subplots_adjust(left=0.05, bottom=0.06, hspace=0.001, wspace=0.001)
    axes = []
    pl.rc("xtick", labelsize=8)
    pl.rc("ytick", labelsize=8)

    for i0 in xrange(nplot):
        for i1 in xrange(nplot):
            if i0 == i1:  # or i1 < i0: # uncomment to keep just one triangle.
                continue
            ax = fig.add_subplot(nplot, nplot, i0 * nplot + i1 + 1)

            y, x = chain[:, i0], chain[:, i1]
            ax.plot(x, y, "r.", ms=1, mew=0)  # , alpha=0.5)
            # y,x = chain[:,i0][P['ijoint_sig'][1]], chain[:,i1][P['ijoint_sig'][1]]
            # ax.plot(x,y,'g.', ms=1.5, mew=0)
            # y,x = chain[:,i0][P['ijoint_sig'][0]], chain[:,i1][P['ijoint_sig'][0]]
            # ax.plot(x,y,'r.', ms=1.5, mew=0)

            ax.plot(P["ml"][i1], P["ml"][i0], "xk", ms=8, mew=2)
            ax.plot(P["ml"][i1], P["ml"][i0], "xr", ms=6, mew=1)

            puttext(0.05, 0.95, P["names"][i0], ax, fontsize=12, va="top")
            puttext(0.95, 0.05, P["names"][i1], ax, fontsize=12, ha="right")
            y0, y1 = np.percentile(chain[:, i0], [5, 95])
            dy = y1 - y0
            ax.set_ylim(y0 - dy, y1 + dy)
            x0, x1 = np.percentile(chain[:, i1], [5, 95])
            dx = x1 - x0
            ax.set_xlim(x0 - dx, x1 + dx)

            c = "crimson"
            if i0 == 0:
                ax.xaxis.set_tick_params(labeltop="on")
                ax.xaxis.set_tick_params(labelbottom="off")
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            elif i0 == nplot - 1 or (i0 == nplot - 2 and i1 == nplot - 1):
                hist_xedge(chain[:, i1], ax, fmt="b", bins=P["bins"][i1], loc="bottom")
                ax.axvline(P["p1sig"][i1][0], ymax=0.2, color=c, lw=0.5)
                ax.axvline(P["p1sig"][i1][1], ymax=0.2, color=c, lw=0.5)
                ax.axvline(P["median"][i1], ymax=0.2, color=c, lw=1.5)
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            else:
                ax.set_xticklabels("")

            if not (i1 == 0 or (i0 == 0 and i1 == 1) or i1 == nplot - 1):
                ax.set_yticklabels("")

            if (i0 == 0 and i1 == 1) or i1 == 0:
                hist_yedge(chain[:, i0], ax, fmt="b", bins=P["bins"][i0], loc="left")
                ax.axhline(P["p1sig"][i0][0], xmax=0.2, color=c, lw=0.5)
                ax.axhline(P["p1sig"][i0][1], xmax=0.2, color=c, lw=0.5)
                ax.axhline(P["median"][i0], xmax=0.2, color=c, lw=1.5)

            if i1 == nplot - 1:
                ax.yaxis.set_tick_params(labelright="on")
                ax.yaxis.set_tick_params(labelleft="off")

            axes.append(ax)

    return fig, axes
Exemple #4
0
def plot_posteriors(chain, P, nplot='all'):
    """ Plot the posterior distributions for a series of parameter
    samples. chain has shape (nsample, nparameters).
    """

    if nplot == 'all':
        nplot = chain.shape[-1]

    #nrows, ncols = get_nrows_ncols(nplot)
    #fig,axes = get_fig_axes(nrows, ncols, nplot)

    fig = pl.figure(figsize=(8.4, 8.4))
    fig.subplots_adjust(left=0.05, bottom=0.06, hspace=0.001, wspace=0.001)
    axes = []
    pl.rc('xtick', labelsize=8)
    pl.rc('ytick', labelsize=8)

    for i0 in xrange(nplot):
        for i1 in xrange(nplot):
            if i0 == i1:  # or i1 < i0: # uncomment to keep just one triangle.
                continue
            ax = fig.add_subplot(nplot, nplot, i0 * nplot + i1 + 1)

            y, x = chain[:, i0], chain[:, i1]
            ax.plot(x, y, 'r.', ms=1, mew=0)  #, alpha=0.5)
            #y,x = chain[:,i0][P['ijoint_sig'][1]], chain[:,i1][P['ijoint_sig'][1]]
            #ax.plot(x,y,'g.', ms=1.5, mew=0)
            #y,x = chain[:,i0][P['ijoint_sig'][0]], chain[:,i1][P['ijoint_sig'][0]]
            #ax.plot(x,y,'r.', ms=1.5, mew=0)

            ax.plot(P['ml'][i1], P['ml'][i0], 'xk', ms=8, mew=2)
            ax.plot(P['ml'][i1], P['ml'][i0], 'xr', ms=6, mew=1)

            puttext(0.05, 0.95, P['names'][i0], ax, fontsize=12, va='top')
            puttext(0.95, 0.05, P['names'][i1], ax, fontsize=12, ha='right')
            y0, y1 = np.percentile(chain[:, i0], [5, 95])
            dy = y1 - y0
            ax.set_ylim(y0 - dy, y1 + dy)
            x0, x1 = np.percentile(chain[:, i1], [5, 95])
            dx = x1 - x0
            ax.set_xlim(x0 - dx, x1 + dx)

            c = 'crimson'
            if i0 == 0:
                ax.xaxis.set_tick_params(labeltop='on')
                ax.xaxis.set_tick_params(labelbottom='off')
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            elif i0 == nplot - 1 or (i0 == nplot - 2 and i1 == nplot - 1):
                hist_xedge(chain[:, i1],
                           ax,
                           fmt='b',
                           bins=P['bins'][i1],
                           loc='bottom')
                ax.axvline(P['p1sig'][i1][0], ymax=0.2, color=c, lw=0.5)
                ax.axvline(P['p1sig'][i1][1], ymax=0.2, color=c, lw=0.5)
                ax.axvline(P['median'][i1], ymax=0.2, color=c, lw=1.5)
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            else:
                ax.set_xticklabels('')

            if not (i1 == 0 or (i0 == 0 and i1 == 1) or i1 == nplot - 1):
                ax.set_yticklabels('')

            if (i0 == 0 and i1 == 1) or i1 == 0:
                hist_yedge(chain[:, i0],
                           ax,
                           fmt='b',
                           bins=P['bins'][i0],
                           loc='left')
                ax.axhline(P['p1sig'][i0][0], xmax=0.2, color=c, lw=0.5)
                ax.axhline(P['p1sig'][i0][1], xmax=0.2, color=c, lw=0.5)
                ax.axhline(P['median'][i0], xmax=0.2, color=c, lw=1.5)

            if i1 == nplot - 1:
                ax.yaxis.set_tick_params(labelright='on')
                ax.yaxis.set_tick_params(labelleft='off')

            axes.append(ax)

    return fig, axes
Exemple #5
0
    ax1.plot(d0.mstar, Rmag0, 'ro')
    ax1.set_ylim(25.38, 26.39)
    ax1.set_xlim(8.3, 10.1)
    make_log_xlabels(ax1)
    ax1.set_xticklabels('')
    ax1.set_ylabel('$r$')
    ax1.text(8.6, 25.58, '$2.3 < z < 2.7$', fontsize=18)
    ax2 = plt.subplot(212)
    ax2.fill_between(xvals, rmg-0.16, y2=rmg+0.16, lw=0, color='0.8')
    ax2.axhline(rmg, ls='--', color='k')
    ax2.plot(d0.mstar, Rmag0-Gmag0, 'go')
    c2 = Rmag0-Gmag0 > 0.5
    #draw_arrows(d0.mstar[c2], 0.02, ax=ax2, ms=1, capsize=5, direction='up')
    ax2.plot([M16, M84],[-0.62]*2, color='0.5', lw=2)
    ax2.plot(M50, -0.62,'o', color='0.5', ms=10, mew=0)
    hist_xedge(d0.mstar, ax2,color='k',bins=10, height=0.35)
    ax2.set_ylim(-0.66, 0.095)
    ax2.set_xlim(8.3, 10.1)
    make_log_xlabels(ax2, yoff=-0.08)
    ax2.set_xlabel('$\mathrm{Stellar\ Mass\ (M_{\odot})}$')
    ax2.set_ylabel('$r-g$')
    #plt.show()

if 1:
    # for paper
    xvals = np.linspace(8,11)
    fig = plt.figure(figsize=(4.2, 4.))
    fig.subplots_adjust(top=0.95, left=0.2, bottom=0.18)
    ax = plt.subplot(111)
    #ax.fill_between(xvals, rmg-0.16, y2=rmg+0.16, lw=0, color='0.85')
    #ax.axhline(rmg, ls='-', color='0.5')
Exemple #6
0
def triplot(names, vals, sigvals, fig, indirect={}, labels=None, fontsize=14):

    from barak.plot import hist_yedge, hist_xedge, puttext
    npar = len(names)
    bins = {}
    for n in names:
        x0, x1 = vals[n].min(), vals[n].max()
        dx = x1 - x0
        lo = x0 - 0.1*dx
        hi = x1 + 0.1*dx
        bins[n] = np.linspace(lo, hi, 20)

    axes = {}
    for i0,n0 in enumerate(names):
        for i1,n1 in enumerate(names):
            if i0 == i1:# or i1 < i0: # uncomment to keep just one triangle.
                continue
            ax = fig.add_subplot(npar,npar, i0 * npar + i1 + 1)
            ax.locator_params(tight=True, nbins=8)
            ax.xaxis.set_minor_locator(AutoMinorLocator())
            ax.yaxis.set_minor_locator(AutoMinorLocator())
            axes[(n0 + ' ' + n1)] = ax

            y,x = vals[n0], vals[n1]
            if USE_HEXBIN:
                ax.hexbin(x,y,cmap=CM, gridsize=40,linewidths=0.1)
            else:
                ax.plot(x,y,'r.', ms=0.5, mew=0)#, alpha=0.5)

            color = 'k' if n0 not in indirect else 'g'
            text = labels[n0] if labels is not None else n0
            puttext(0.05, 0.95, text, ax, color=color ,fontsize=fontsize, va='top')
            color = 'k' if n1 not in indirect else 'g'
            text = labels[n1] if labels is not None else n1
            puttext(0.95, 0.08, text, ax, color=color ,fontsize=fontsize, ha='right')
            # set limits
            y0, y1 = np.percentile(vals[n0], [5, 95])
            dy = y1 - y0
            ax.set_ylim(y0 - dy, y1 + dy)
            x0, x1 = np.percentile(vals[n1], [5, 95])
            dx = x1 - x0
            ax.set_xlim(x0 - dx, x1 + dx)

            c = 'k'
            if i0 == 0:
                ax.xaxis.set_tick_params(labeltop='on')
                ax.xaxis.set_tick_params(labelbottom='off')
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            elif i0 == npar-1 or (i0 == npar-2 and i1 == npar-1):
                hist_xedge(vals[n1], ax, color='forestgreen',
                           fill=dict(color='forestgreen',alpha=0.3),
                           bins=bins[n1], loc='bottom')
                ax.axvline(sigvals[n1][0], ymax=0.2, color=c, lw=0.5)
                ax.axvline(sigvals[n1][1], ymax=0.2, color=c, lw=0.5)
                cen = sum(sigvals[n1]) / 2.
                ax.axvline(cen, ymax=0.2, color=c, lw=1.5)
                for t in ax.get_xticklabels():
                    t.set_rotation(60)
            else:
                ax.set_xticklabels('')

            if not (i1 == 0 or (i0 == 0 and i1 == 1) or i1 == npar-1):
                ax.set_yticklabels('')

            if (i0 == 0 and i1 == 1) or i1 == 0:
                hist_yedge(vals[n0], ax, color='forestgreen',
                           fill=dict(color='forestgreen',alpha=0.3),
                           bins=bins[n0], loc='left')
                ax.axhline(sigvals[n0][0], xmax=0.2, color=c, lw=0.5)
                ax.axhline(sigvals[n0][1], xmax=0.2, color=c, lw=0.5)
                cen = sum(sigvals[n0]) / 2.
                ax.axhline(cen, xmax=0.2, color=c, lw=1.5)

            if i1 == npar - 1:
                ax.yaxis.set_tick_params(labelright='on')
                ax.yaxis.set_tick_params(labelleft='off')

            #ax.minorticks_on()

    return axes
Exemple #7
0
    ax1.plot(d0.mstar, Rmag0, 'ro')
    ax1.set_ylim(25.38, 26.39)
    ax1.set_xlim(8.3, 10.1)
    make_log_xlabels(ax1)
    ax1.set_xticklabels('')
    ax1.set_ylabel('$r$')
    ax1.text(8.6, 25.58, '$2.3 < z < 2.7$', fontsize=18)
    ax2 = plt.subplot(212)
    ax2.fill_between(xvals, rmg - 0.16, y2=rmg + 0.16, lw=0, color='0.8')
    ax2.axhline(rmg, ls='--', color='k')
    ax2.plot(d0.mstar, Rmag0 - Gmag0, 'go')
    c2 = Rmag0 - Gmag0 > 0.5
    #draw_arrows(d0.mstar[c2], 0.02, ax=ax2, ms=1, capsize=5, direction='up')
    ax2.plot([M16, M84], [-0.62] * 2, color='0.5', lw=2)
    ax2.plot(M50, -0.62, 'o', color='0.5', ms=10, mew=0)
    hist_xedge(d0.mstar, ax2, color='k', bins=10, height=0.35)
    ax2.set_ylim(-0.66, 0.095)
    ax2.set_xlim(8.3, 10.1)
    make_log_xlabels(ax2, yoff=-0.08)
    ax2.set_xlabel('$\mathrm{Stellar\ Mass\ (M_{\odot})}$')
    ax2.set_ylabel('$r-g$')
    #plt.show()

if 1:
    # for paper
    xvals = np.linspace(8, 11)
    fig = plt.figure(figsize=(4.2, 4.))
    fig.subplots_adjust(top=0.95, left=0.2, bottom=0.18)
    ax = plt.subplot(111)
    #ax.fill_between(xvals, rmg-0.16, y2=rmg+0.16, lw=0, color='0.85')
    #ax.axhline(rmg, ls='-', color='0.5')