Exemplo n.º 1
0
 def rplot(data, par={}, title={}, xlab="", ylab=""):
     r.plot_new()
     xmax = -1e6
     xmin = 1e6
     ymax = -1e6
     ymin = 1e6
     for x in data:
         #print x[0]
         #print x[1]
         xmax = max(xmax, max(x[0]))
         xmin = min(xmin, min(x[0]))
         ymax = max(ymax, max(x[1]))
         ymin = min(ymin, min(x[1]))
         #print xmin, xmax, ymin, ymax
     r.plot_window(xlim=(xmin, xmax), ylim=(ymin, ymax))
     r.title(
         main=title.get("main", ""),
         xlab=title.get("xlab", ""),
         ylab=title.get("ylab", ""))
     r.box(col="black") ; r.axis(1) ; r.axis(2)
     for i, x in enumerate(data):
         r.lines(x[0], x[1], col=i+1, **par)
Exemplo n.º 2
0
def myhist(lnw, color="black", makenewplot=True, main=None, bins=None, support=None, xlab=None, ylab="", sub=None, xmin=None, xmax=None, bin_numbers=True):
    nbins = len(lnw)

    if bins!=None:
        assert(nbins==len(bins)-1)

    xss = [[]]
    yss = [[]]
    xlim = None
    connect_to_prev = False
    
    if bins==None:
        for bin in range(nbins):
            if (lnw[bin] > -inf or lnw[bin] < inf) and (support==None or support[bin]) and (xmin==None or xmin<=bin) and (xmax==None or (bin+1)<=xmax):
                xss[-1] += [bin, bin+1]
                yss[-1] += [lnw[bin], lnw[bin]]

            elif xss[-1]!=[]:
                xss.append([])
                yss.append([])

        if xmin==None and xmax==None:
            xlim = (0, nbins+1)
        else:
            xs = reduce(operator.add, xss, [])
            xlim = (min(xs), max(xs))
    else:
        for bin in range(nbins):
            if (lnw[bin] > -inf or lnw[bin] < inf) and (support==None or support[bin]) and (xmin==None or xmin<=bins[bin]) and (xmax==None or bins[bin+1]<=xmax):
                xss[-1] += [bins[bin], bins[bin+1]]
                yss[-1] += [lnw[bin], lnw[bin]]

            elif xss[-1]!=[]:
                xss.append([])
                yss.append([])

        if xmin==None and xmax==None:
            xlim = (bins[0], bins[-1])
        else:
            xs = reduce(operator.add, xss, [])
            xlim = (min(xs), max(xs))

    # Do the plotting
    if makenewplot:
        r.plot_new()

        ys = reduce(operator.add, yss, [])
        ymin = min(ys)
        ymax = max(ys)
        
        r.plot_window(xlim=xlim, ylim=(ymin, ymax))

        if bins!=None and bin_numbers:
            labels = array(r.pretty(range(nbins), 8), dtype=int)
            labels = labels[(0<=labels) & (labels<nbins)]
            ats = bins[labels]

            r.axis(1)
            r.axis(1, tick=False, labels=labels, at=ats, mgp=(3,2,0))
            r.axis(2)

            this_xlab = "E, bin"
        else:
            r.axis(1)
            r.axis(2)

            this_xlab = "E"
        
        r.axis(1)
        r.axis(2)
        r.box()
        r.title(ylab=ylab)

        if xlab==None:
            r.title(xlab=this_xlab)
        else:
            r.title(xlab=xlab)
        
        if main!=None:
            r.title(main=main)

        if sub!=None:
            r.title(sub=sub)

    for (xs, ys) in zip(xss, yss):
        r.lines(xs, ys, col=color, lwd=0.5)

    return (xss, yss)