示例#1
0
    def doplot(self):
        tab = Table(2, 1)
        tab.title = self.title

        xfit, yfit, gprior = self.get_prior_vals()

        nrand = 100000
        binsize = self.binsize
        h = self.h
        h1 = self.h1
        h2 = self.h2

        g1rand, g2rand = gprior.sample2d(nrand)
        grand = gprior.sample1d(nrand)

        hrand = histogram(grand, binsize=binsize, min=0.0, max=1.0, more=True)
        h1rand = histogram(g1rand, binsize=binsize, min=-1.0, max=1.0, more=True)

        fbinsize = xfit[1] - xfit[0]
        hrand["hist"] = hrand["hist"] * float(yfit.sum()) / hrand["hist"].sum() * fbinsize / binsize
        h1rand["hist"] = h1rand["hist"] * float(h1["hist"].sum()) / h1rand["hist"].sum()

        pltboth = FramedPlot()
        pltboth.xlabel = r"$g$"

        hplt1 = Histogram(h1["hist"], x0=h1["low"][0], binsize=binsize, color="red")
        hplt2 = Histogram(h2["hist"], x0=h2["low"][0], binsize=binsize, color="blue")
        hpltrand = Histogram(hrand["hist"], x0=hrand["low"][0], binsize=binsize, color="magenta")
        hplt1rand = Histogram(h1rand["hist"], x0=h1rand["low"][0], binsize=binsize, color="magenta")

        hplt1.label = r"$g_1$"
        hplt2.label = r"$g_2$"
        hplt1rand.label = "rand"
        hpltrand.label = "rand"
        keyboth = PlotKey(0.9, 0.9, [hplt1, hplt2, hplt1rand], halign="right")

        pltboth.add(hplt1, hplt2, hplt1rand, keyboth)
        tab[0, 0] = pltboth

        plt = FramedPlot()
        plt.xlabel = r"$|g|$"

        hplt = Histogram(h["hist"], x0=h["low"][0], binsize=binsize)
        hplt.label = "|g|"

        line = Curve(xfit, yfit, color="blue")
        line.label = "model"

        key = PlotKey(0.9, 0.9, [hplt, line, hpltrand], halign="right")
        plt.add(line, hplt, hpltrand, key)

        tab[1, 0] = plt

        if self.show:
            tab.show()

        return tab
示例#2
0
    def doplot(self, fitres, h, minmag, maxmag):
        tab=biggles.Table(2,1)

        plt=FramedPlot()
        plt.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag)
        plt.xlabel=r'$\sigma$'

        sprior=fitres.get_model()

        nrand=100000
        binsize=self.binsize

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='data'

        srand=sprior.sample(nrand)
        hrand=histogram(srand, binsize=binsize, min=h['low'][0], max=h['high'][-1], more=True)
        hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand

        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize,
                           color='blue')
        hpltrand.label='rand'


        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')

        plt.add(hplt, hpltrand, key)

        
        tplt=fitres.plot_trials(show=False,fontsize_min=0.88888888)
        
        tab[0,0] = plt
        tab[1,0] = tplt

        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofs-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.objtype)
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)

        return tab
示例#3
0
    def doplot(self, gprior, minmag, maxmag):
        from lensing.util import eta1eta2_to_g1g2

        tab = Table(2, 2)
        tab.title = "%s %.2f %.2f " % (self.otype, minmag, maxmag)

        h1_g, h2_g, h_g = self.do_histograms(minmag, maxmag, "g")
        h1_eta, h2_eta, h_eta = self.do_histograms(minmag, maxmag, "eta")

        nrand = 1000000
        binsize_eta = self.binsize_eta
        binsize_g = self.binsize_g

        rbinsize_eta = binsize_eta * 0.2
        rbinsize_g = binsize_g * 0.2

        gr = gprior.sample(nrand)
        eta1_rand = gr[:, 0]
        eta2_rand = gr[:, 1]
        eta_rand = numpy.sqrt(eta1_rand ** 2 + eta2_rand ** 2)

        g1_rand, g2_rand = eta1eta2_to_g1g2(eta1_rand, eta2_rand)
        g_rand = numpy.sqrt(g1_rand ** 2 + g2_rand ** 2)

        hrand_eta = histogram(eta_rand, binsize=rbinsize_eta, min=0, max=self.max_eta, more=True)
        h1rand_eta = histogram(eta1_rand, binsize=rbinsize_eta, min=self.min_eta_2d, max=self.max_eta_2d, more=True)

        hrand_g = histogram(g_rand, binsize=rbinsize_g, min=0, max=self.max_g, more=True)
        h1rand_g = histogram(g1_rand, binsize=rbinsize_g, min=self.min_g_2d, max=self.max_g_2d, more=True)

        # eta 2d plots
        bratio_eta = self.binsize_eta / rbinsize_eta
        hrand_eta["hist"] = hrand_eta["hist"] * bratio_eta * float(h_eta["hist"].sum()) / nrand
        h1rand_eta["hist"] = h1rand_eta["hist"] * bratio_eta * float(h1_eta["hist"].sum()) / h1rand_eta["hist"].sum()

        pltboth_eta = FramedPlot()
        pltboth_eta.xlabel = r"$\eta$"

        hplt1_eta = Histogram(h1_eta["hist"], x0=h1_eta["low"][0], binsize=binsize_eta, color="darkgreen")
        hplt2_eta = Histogram(h2_eta["hist"], x0=h2_eta["low"][0], binsize=binsize_eta, color="blue")
        hpltrand_eta = Histogram(hrand_eta["hist"], x0=hrand_eta["low"][0], binsize=rbinsize_eta, color="red")
        hplt1rand_eta = Histogram(h1rand_eta["hist"], x0=h1rand_eta["low"][0], binsize=rbinsize_eta, color="red")

        hplt1_eta.label = r"$\eta_1$"
        hplt2_eta.label = r"$\eta_2$"
        hplt1rand_eta.label = "rand"
        hpltrand_eta.label = "rand"
        keyboth_eta = PlotKey(0.9, 0.9, [hplt1_eta, hplt2_eta, hplt1rand_eta], halign="right")

        pltboth_eta.add(hplt1_eta, hplt2_eta, hplt1rand_eta, keyboth_eta)

        tab[0, 0] = pltboth_eta

        plt1d_eta = FramedPlot()
        plt1d_eta.xlabel = r"$|\eta|$"

        hplt_eta = Histogram(h_eta["hist"], x0=h_eta["low"][0], binsize=binsize_eta)
        hplt_eta.label = r"$|\eta|$"

        key_eta = PlotKey(0.9, 0.9, [hplt_eta, hpltrand_eta], halign="right")
        plt1d_eta.add(hplt_eta, hpltrand_eta, key_eta)

        tab[1, 0] = plt1d_eta

        # g plots

        bratio_g = self.binsize_g / rbinsize_g
        hrand_g["hist"] = hrand_g["hist"] * bratio_g * float(h_g["hist"].sum()) / nrand
        h1rand_g["hist"] = h1rand_g["hist"] * bratio_g * float(h1_g["hist"].sum()) / h1rand_g["hist"].sum()

        pltboth_g = FramedPlot()
        pltboth_g.xlabel = r"$g$"

        hplt1_g = Histogram(h1_g["hist"], x0=h1_g["low"][0], binsize=binsize_g, color="darkgreen")
        hplt2_g = Histogram(h2_g["hist"], x0=h2_g["low"][0], binsize=binsize_g, color="blue")
        hpltrand_g = Histogram(hrand_g["hist"], x0=hrand_g["low"][0], binsize=rbinsize_g, color="red")
        hplt1rand_g = Histogram(h1rand_g["hist"], x0=h1rand_g["low"][0], binsize=rbinsize_g, color="red")

        hplt1_g.label = r"$g_1$"
        hplt2_g.label = r"$g_2$"
        hplt1rand_g.label = "rand"
        hpltrand_g.label = "rand"
        keyboth_g = PlotKey(0.9, 0.9, [hplt1_g, hplt2_g, hplt1rand_g], halign="right")

        pltboth_g.add(hplt1_g, hplt2_g, hplt1rand_g, keyboth_g)

        tab[0, 1] = pltboth_g

        plt1d_g = FramedPlot()
        plt1d_g.xlabel = r"$|g|$"

        hplt_g = Histogram(h_g["hist"], x0=h_g["low"][0], binsize=binsize_g)
        hplt_g.label = "|g|"

        key_g = PlotKey(0.9, 0.9, [hplt_g, hpltrand_g], halign="right")
        plt1d_g.add(hplt_g, hpltrand_g, key_g)

        tab[1, 1] = plt1d_g

        if self.show:
            tab.show()

        d = files.get_prior_dir()
        d = os.path.join(d, "plots")
        epsfile = "pofe-pofeta-%.2f-%.2f-%s.eps" % (minmag, maxmag, self.otype)
        epsfile = os.path.join(d, epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system("converter -d 100 %s" % epsfile)

        return tab
示例#4
0
    def doplot(self, fitres, h1, h2, h, minmag, maxmag):
        tab=Table(2,1)
        tab.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag)

        #xfit,yfit,gprior = self.get_prior_vals(fitres, h)
        gprior=self.get_prior(fitres)

        nrand=100000
        binsize=self.binsize


        g1rand,g2rand=gprior.sample2d(nrand)
        grand=gprior.sample1d(nrand)

        hrand=histogram(grand, binsize=binsize, min=0., max=1., more=True)
        h1rand=histogram(g1rand, binsize=binsize, min=-1., max=1., more=True)

        #fbinsize=xfit[1]-xfit[0]
        #hrand['hist'] = hrand['hist']*float(yfit.sum())/hrand['hist'].sum()*fbinsize/binsize
        hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand
        h1rand['hist'] = h1rand['hist']*float(h1['hist'].sum())/h1rand['hist'].sum()


        pltboth=FramedPlot()
        pltboth.xlabel=r'$g$'

        hplt1=Histogram(h1['hist'], x0=h1['low'][0], binsize=binsize,color='red')
        hplt2=Histogram(h2['hist'], x0=h2['low'][0], binsize=binsize,color='blue')
        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize,
                           color='magenta')
        hplt1rand=Histogram(h1rand['hist'], x0=h1rand['low'][0], binsize=binsize,
                           color='magenta')

        hplt1.label=r'$g_1$'
        hplt2.label=r'$g_2$'
        hplt1rand.label='rand'
        hpltrand.label='rand'
        keyboth=PlotKey(0.9,0.9,[hplt1,hplt2,hplt1rand],halign='right')

        pltboth.add(hplt1, hplt2, hplt1rand, keyboth)
        tab[0,0]=pltboth
        

        plt=FramedPlot()
        plt.xlabel=r'$|g|$'

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='|g|'

        
        #line=Curve(xfit, yfit, color='blue')
        #line.label='model'

        #key=PlotKey(0.9,0.9,[hplt,line,hpltrand],halign='right')
        #plt.add(line, hplt, hpltrand, key)
        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')
        plt.add(hplt, hpltrand, key)


        tab[1,0]=plt
        
        if self.show:
            tab.show()

        return tab
示例#5
0
文件: sg.py 项目: esheldon/espy
def test(data=None, logc=False):
    from biggles import Histogram, FramedPlot, PlotKey, Table
    if data is None:
        data = read_test_data()

    
    modelflux, modelflux_ivar = avg_gri(data['modelflux'][:,1],data['modelflux_ivar'][:,1],
                                        data['modelflux'][:,2],data['modelflux_ivar'][:,2],
                                        data['modelflux'][:,3],data['modelflux_ivar'][:,3])
    #psfflux, psfflux_ivar = avg_gri(data['psfflux'][:,1],data['psfflux_ivar'][:,1],
    #                                data['psfflux'][:,2],data['psfflux_ivar'][:,2],
    #                                data['psfflux'][:,3],data['psfflux_ivar'][:,3])
    psfflux, psfflux_ivar = avg_gri(data['psfflux'][:,1],data['modelflux_ivar'][:,1],
                                    data['psfflux'][:,2],data['modelflux_ivar'][:,2],
                                    data['psfflux'][:,3],data['modelflux_ivar'][:,3])

    fmin_log=1.e-3
    fmax_log=4.


    tab = Table(2,2)
    binsize=0.05
    col=0
    for type in ['modelflux','psfflux']:

        flux_plt = FramedPlot()

        h = eu.stat.histogram(log10(data[type][:,1]), min=fmin_log, max=fmax_log, binsize=binsize)
        gmod_h = Histogram(h, x0=fmin_log, binsize=binsize, color='green')
        gmod_h.label = 'g '+type

        h = eu.stat.histogram(log10(data[type][:,2]), min=fmin_log, max=fmax_log, binsize=binsize)
        rmod_h = Histogram(h, x0=fmin_log, binsize=binsize, color='red')
        rmod_h.label = 'r '+type

        h = eu.stat.histogram(log10(data[type][:,3]), min=fmin_log, max=fmax_log, binsize=binsize)
        imod_h = Histogram(h, x0=fmin_log, binsize=binsize, color='magenta')
        imod_h.label = 'i '+type


        if type == 'modelflux':
            h = eu.stat.histogram(log10(modelflux), min=fmin_log, max=fmax_log, binsize=binsize)
        else:
            h = eu.stat.histogram(log10(psfflux), min=fmin_log, max=fmax_log, binsize=binsize)

        mod_h = Histogram(h, x0=fmin_log, binsize=binsize, width=2)
        mod_h.label = 'combined '+type

        key = PlotKey(0.5,0.9,[gmod_h, rmod_h, imod_h, mod_h])
        
        flux_plt.add(gmod_h, rmod_h, imod_h, mod_h, key)
        flux_plt.xlabel = 'flux'

        tab[0,col] = flux_plt

        col += 1



    col=0
    for logc in [False,True]:
        if logc:
            xmin=-0.1
            #xmax=1
            xmax=0.6
            binsize = 0.01
        else:
            xmin=-0.1
            xmax=1.0
            binsize = 0.01

        gc = calc_c(data['modelflux'][:,1], data['psfflux'][:,1], log=logc)
        rc = calc_c(data['modelflux'][:,2], data['psfflux'][:,2], log=logc)
        ic = calc_c(data['modelflux'][:,3], data['psfflux'][:,3], log=logc)
        allc = calc_c(modelflux, psfflux, log=logc)
        
        c_plt = FramedPlot()

        h = eu.stat.histogram(gc, min=xmin, max=xmax, binsize=binsize)
        gch = Histogram(h, x0=xmin, binsize=binsize, color='green')
        gch.label = 'g'

        h = eu.stat.histogram(rc, min=xmin, max=xmax, binsize=binsize)
        rch = Histogram(h, x0=xmin, binsize=binsize, color='red')
        rch.label = 'r'

        h = eu.stat.histogram(ic, min=xmin, max=xmax, binsize=binsize)
        ich = Histogram(h, x0=xmin, binsize=binsize, color='magenta')
        ich.label = 'i'


        h = eu.stat.histogram(allc, min=xmin, max=xmax, binsize=binsize)
        ch = Histogram(h, x0=xmin, binsize=binsize, width=2)
        ch.label = 'combined '

        key = PlotKey(0.7,0.9,[gch, rch, ich, ch])
        
        c_plt.add(gch, rch, ich, ch, key)
        if logc:
            c_plt.xlabel = r'$-log_{10}(psf/model)$'
        else:
            c_plt.xlabel = '1-psf/model'

        tab[1,col] = c_plt
        col += 1

    tab.show()
示例#6
0
    def doplot(self, gprior, h1, h2, h, minmag, maxmag):
        tab=Table(2,1)
        tab.title='%s %.2f %.2f ' % (self.otype, minmag, maxmag)


        nrand=1000000
        binsize=self.binsize
        rbinsize=binsize*0.2


        gr = gprior.sample(nrand)
        g1rand=gr[:,0]
        g2rand=gr[:,1]

        grand = numpy.sqrt( g1rand**2 + g2rand**2 )

        #hrand=histogram(grand, binsize=rbinsize, min=h['low'][0], max=h['high'][-1], more=True)
        hrand=histogram(grand, binsize=rbinsize, min=0,max=self.maxe, more=True)
        h1rand=histogram(g1rand, binsize=rbinsize, min=self.mine_2d, max=self.maxe_2d, more=True)

        bratio = self.binsize/rbinsize
        hrand['hist'] = hrand['hist']*bratio*float(h['hist'].sum())/nrand
        h1rand['hist'] = h1rand['hist']*bratio*float(h1['hist'].sum())/h1rand['hist'].sum()


        pltboth=FramedPlot()
        pltboth.xlabel=r'$%s$' % self.ellip_name

        hplt1=Histogram(h1['hist'], x0=h1['low'][0], binsize=binsize,color='darkgreen')
        hplt2=Histogram(h2['hist'], x0=h2['low'][0], binsize=binsize,color='blue')
        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=rbinsize,
                           color='red')
        hplt1rand=Histogram(h1rand['hist'], x0=h1rand['low'][0], binsize=rbinsize,
                           color='red')

        hplt1.label=r'$g_1$'
        hplt2.label=r'$g_2$'
        hplt1rand.label='rand'
        hpltrand.label='rand'
        keyboth=PlotKey(0.9,0.9,[hplt1,hplt2,hplt1rand],halign='right')

        pltboth.add(hplt1, hplt2, hplt1rand, keyboth)


        tab[0,0]=pltboth
        

        plt=FramedPlot()
        plt.xlabel=r'$|%s|$' % self.ellip_name

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='|%s|' % self.ellip_name

        
        #line=Curve(xfit, yfit, color='blue')
        #line.label='model'

        #key=PlotKey(0.9,0.9,[hplt,line,hpltrand],halign='right')
        #plt.add(line, hplt, hpltrand, key)
        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')
        plt.add(hplt, hpltrand, key)


        tab[1,0]=plt
        
        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofe-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.otype)
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)

        return tab
示例#7
0
def plot_lens_s2n(zl, zslow, zshigh, pzs, cumulative=True):
    """

    Calculate the cumulative expected usefulness of lenses as a function of
    redshift for the given source N(z).

    """

    import biggles
    from biggles import FramedPlot, Curve, PlotLabel, PlotKey, Table, Histogram

    biggles.configure('screen','width',1140)
    biggles.configure('screen','height',1140)
    nzl=zshigh.size
    zlmin = 0.0
    zlmax = max([zl.max(), zshigh.max()])

    # first get the mean inverse critical density as a function
    # of lens redshift
    zsmid = (zshigh+zslow)/2.
    sc = lensing.sigmacrit.ScinvCalculator(zlmin, zlmax, nzl, zsmid[0], zsmind[-1])

    mean_scinv = sc.calc_mean_scinv(pzs)


    # histogram the lens redshifts in a binning corresponding
    # to the mean_scinv

    hdict = eu.stat.histogram(zl, min=zlmin, max=zlmax, binsize=dz, more=True)

    # get distances to the bin centers
    cosmo=cosmology.Cosmo()
    Dlens = cosmo.Da(0.0, hdict['center'])

    # interpolate the mean_scinv onto the centers
    mean_scinv = eu.stat.interplin(mean_scinv, sc.zlvals, hdict['center'])

    # this is the S/N at a given lens redshift
    s2n = sqrt(hdict['hist']/Dlens**2)*mean_scinv

    hd = hdict['hist']/Dlens**2
    hdcum = hd.cumsum()
    s2ncum = (mean_scinv*hd).cumsum()/sqrt(hdcum.clip(1.,hdcum.max()))


    s2n /= s2n.max()
    s2ncum /= s2ncum.max()

    
    tab = Table(2,2)
    tab.aspect_ratio=1

    # redshift histograms
    tab[0,0] = FramedPlot()
    zl_histp = Histogram(hdict['hist']/float(hdict['hist'].sum()), x0=hdict['low'][0], binsize=dz, color='blue')
    zl_histp.label = 'lenses'
    zs_histp = Histogram(pzs/float(pzs.sum()), x0=zslow[0], binsize=dz, color='red')
    zs_histp.label = 'sources'

    hkey=PlotKey(0.9,0.9,[zl_histp,zs_histp],halign='right')
    tab[0,0].add(zl_histp, zs_histp, hkey)
    tab[0,0].xlabel = 'z'

    # mean inverse critical density
    tab[0,1] = FramedPlot()
    tab[0,1].xlabel = 'lens redshift'
    tab[0,1].ylabel = r'$\langle \Sigma_{crit}^{-1} \rangle$'

    mc = Curve(hdict['center'], mean_scinv)
    tab[0,1].add(mc)


    # cumulative volume
    tab[1,0] = FramedPlot()
    tab[1,0].xlabel = 'z'
    tab[1,0].ylabel = 'cumulative volume'
    v=zeros(hdict['center'].size)
    for i in xrange(v.size):
        v[i] = cosmo.V(0.0, hdict['center'][i])
    v /= v.max()
    cv=Curve(hdict['center'], v)
    tab[1,0].add(cv)


    # S/N
    tab[1,1] = FramedPlot()
    tab[1,1].xlabel = 'lens redshift'
    tab[1,1].ylabel = 'S/N'

    cs2n = Curve(hdict['center'], s2n, color='blue')
    cs2ncum = Curve(hdict['center'], s2ncum, color='red')

    cs2n.label = 'S/N'
    cs2ncum.label = 'Cumulative S/N'
    ckey=PlotKey(0.9,0.9,[cs2n, cs2ncum],halign='right')

    tab[1,1].add(cs2n, cs2ncum, ckey)


    tab.show()

    return tab
示例#8
0
    def doplot(self, fitres, h1, h2, h, minmag, maxmag):
        tab=Table(2,1)
        tab.title='%s %.2f %.2f ' % (self.objtype, minmag, maxmag)

        #xfit,yfit,gprior = self.get_prior_vals(fitres, h)
        gprior=self.get_prior(fitres)

        nrand=100000
        binsize=self.binsize


        g1rand,g2rand=gprior.sample2d(nrand)
        grand=gprior.sample1d(nrand)

        #hrand=histogram(grand, binsize=binsize, min=0., max=1., more=True)
        hrand=histogram(grand, binsize=binsize, min=h['low'][0], max=h['high'][-1], more=True)
        h1rand=histogram(g1rand, binsize=binsize, min=-1., max=1., more=True)

        #fbinsize=xfit[1]-xfit[0]
        #hrand['hist'] = hrand['hist']*float(yfit.sum())/hrand['hist'].sum()*fbinsize/binsize
        hrand['hist'] = hrand['hist']*float(h['hist'].sum())/nrand
        h1rand['hist'] = h1rand['hist']*float(h1['hist'].sum())/h1rand['hist'].sum()


        pltboth=FramedPlot()
        pltboth.xlabel=r'$g$'

        hplt1=Histogram(h1['hist'], x0=h1['low'][0], binsize=binsize,color='red')
        hplt2=Histogram(h2['hist'], x0=h2['low'][0], binsize=binsize,color='blue')
        hpltrand=Histogram(hrand['hist'], x0=hrand['low'][0], binsize=binsize,
                           color='magenta')
        hplt1rand=Histogram(h1rand['hist'], x0=h1rand['low'][0], binsize=binsize,
                           color='magenta')

        hplt1.label=r'$g_1$'
        hplt2.label=r'$g_2$'
        hplt1rand.label='rand'
        hpltrand.label='rand'
        keyboth=PlotKey(0.9,0.9,[hplt1,hplt2,hplt1rand],halign='right')

        pltboth.add(hplt1, hplt2, hplt1rand, keyboth)
        tab[0,0]=pltboth
        

        plt=FramedPlot()
        plt.xlabel=r'$|g|$'

        hplt=Histogram(h['hist'], x0=h['low'][0], binsize=binsize)
        hplt.label='|g|'

        
        #line=Curve(xfit, yfit, color='blue')
        #line.label='model'

        #key=PlotKey(0.9,0.9,[hplt,line,hpltrand],halign='right')
        #plt.add(line, hplt, hpltrand, key)
        key=PlotKey(0.9,0.9,[hplt,hpltrand],halign='right')
        plt.add(hplt, hpltrand, key)


        tab[1,0]=plt
        
        if self.show:
            tab.show()

        d=files.get_prior_dir()
        d=os.path.join(d, 'plots')
        epsfile='pofe-%.2f-%.2f-%s.eps' % (minmag,maxmag,self.objtype)
        epsfile=os.path.join(d,epsfile)
        eu.ostools.makedirs_fromfile(epsfile)
        print epsfile
        tab.write_eps(epsfile)
        os.system('converter -d 100 %s' % epsfile)

        return tab