コード例 #1
0
ファイル: plotting.py プロジェクト: esheldon/espy
def plot2dsig(r1, dsig1, dsig1err, r2, dsig2, dsig2err, **keys):
    """
    Plot delta sigma and a second delta sigma in two plots the second of which
    is linear.

    Parameters
    ----------
    show: bool, optional
        Show plot in a window, default True
    yrange1: [min,max]
        The y range of the delta sigma plot
    yrange2: [min,max]
        The y range of the ortho-delta sigma plot
    range4var: [min,max]
        The x range over which to calculate a osig variance
        and determine a plot range.  This is overridden by
        range2

    plot_label: string, optional
        a label for the top plot

    # label1,label2 go in a key in the bottom plot
    label1: string, optional
        a label for the first dsig
    label2: string, optional
        a label for the second dsig


    """

    color2 = 'red'
    ptype1='filled circle'
    size1=1.5
    ptype2='filled circle'
    size2=1.5

    xmul = keys.get('xmul',1.)

    show = keys.get('show',True)
    yrange1 = keys.get('yrange1',None)
    yrange2 = keys.get('yrange2',None)

    isortho = keys.get('ortho',False)

    # this is a y-log plot, use more powerful range determination
    print dsig1
    print dsig1err
    yrange1 = eu.plotting.get_log_plot_range(dsig1, err=dsig1err, 
                                             input_range=yrange1)

    rr=numpy.concatenate((r1,r2))
    xrng = eu.plotting.get_log_plot_range(rr)

    # this over-rides
    range4var = keys.get('range4var',None)
    if yrange2 is None:
        if range4var is not None:
            w=where1( (r2 >= range4var[0]) & (r2 <= range4var[1]))
            if w.size == 0:
                raise ValueError("no points in range [%d,%d]" % tuple(range4var))
            sdev = dsig2[w].std()
        else:
            sdev = dsig2.std()

        yrange2 = [-3.5*sdev, 3.5*sdev]


    label  = keys.get('plot_label',None)
    label1 = keys.get('label1',None)
    label2 = keys.get('label2',None)

    # The points and zero curve
    dsig1_p = Points(r1, dsig1, color='black', type=ptype1, size=size1)
    dsig1err_p = SymErrY(r1, dsig1, dsig1err, color='black')
    dsig1_p.label=label1

    dsig2_p = Points(r2*xmul, dsig2, color=color2, type=ptype2, size=size2)
    dsig2err_p = SymErrY(r2*xmul, dsig2, dsig2err, color=color2)
    dsig2_p.label=label2

    c=Curve([1.e-5,1.e5],[0,0], type='solid')


    arr = FramedArray(2,1)
    arr.cellspacing=1
    arr.aspect_ratio=2
    arr.xlabel = labels['rproj']
    if isortho:
        arr.ylabel = labels['osig']
    else:
        arr.ylabel = labels['dsig']
    arr.xrange = xrng


    arr[0,0].yrange = yrange1
    arr[0,0].xlog=True
    arr[0,0].ylog=True

    # biggles chokes if you give it negative data for a log plot
    arr[0,0].add(dsig1_p, dsig2_p)
    eu.plotting.add_log_error_bars(arr[0,0],'y',r1,dsig1,dsig1err,yrange1)
    eu.plotting.add_log_error_bars(arr[0,0],'y',r2,dsig2,dsig2err,yrange1,color=color2)

    if label is not None:
        arr[0,0].add(PlotLabel(0.9,0.9,label,halign='right'))


    arr[1,0].yrange = yrange2
    arr[1,0].xlog=True
    arr[1,0].add(c)
    arr[1,0].add(dsig1_p, dsig1err_p, dsig2_p, dsig2err_p)

    if label1 is not None or label2 is not None:
        key = PlotKey(0.9,0.15, [dsig1_p,dsig2_p], halign='right')
        arr[1,0].add(key)


    if show:
        arr.show()
    return arr