예제 #1
0
def scatter_range(dates, collist, multiplot=False, axes=None, legendloc='best', legend_labels=False, **kwargs):
    """Scatterplot of the collist of the dates range given."""
    if len(collist) != 2:
        raise ValueError("Expected two entries in collist")

    # Fetch prep data fetching
    sorted_dates = sorted(dates)
    if multiplot:
        all_labels = db.fetch_range(sorted_dates, [multiplot])
        labels = []
        [labels.append(k) for k in all_labels if k not in labels]
    else:
        labels = ['']

    datalist = []
    alldates = db.fetch_range(sorted_dates, ['date'])
    fetch_dict = {'date':alldates}
    for label in labels:
        if multiplot:
            fetch_dict[multiplot] = [label]
        raw_data = db.fetch_matching(fetch_dict, collist)
        datalist.append(np.array(raw_data))

    # Plot all that juicy data
    mark = list(__MARKS)
    for data, label in zip(datalist, labels):
        x, y, ystd = lib.avg_copies(data)
        ax = scatter(x, y, ystd, collist[0], collist[1], label=label, fmt='.', marker=mark.pop(0), **kwargs)
    if multiplot:
        ax.legend(loc=legendloc)
        handles, labels = ax.get_legend_handles_labels()
        handles = [h[0] for h in handles]
        if legend_labels:
            labels = legend_labels
        ax.legend(handles, labels, loc=legendloc, numpoints=1)

    # adjust the lims
    xmin = min(x)
    xmax = max(x)
    ymin, ymax = ax.get_ylim()
    tmpy = ymax-ymin
    ymin, ymax = (ymin-0.05*tmpy, ymax+0.05*tmpy)
    tmpx = xmax-xmin
    xmin, xmax = (xmin-0.05*tmpx, xmax+0.05*tmpx)
    ax.set_ylim([ymin,ymax])
    ax.set_xlim([xmin,xmax])

    # Save shit
    cols_savename = collist + [multiplot] if multiplot else collist
    sname = GRAPHDUMP_OUTPUT_LOCATION + '-'.join(cols_savename) +\
            '_' + '-'.join([lib.base62_encode(x) for x in sorted_dates])
    save(sname)

    return ax
예제 #2
0
def time_offset_cdf(dates, bins=10000, axes=None, savename='', cplen=5.6, truncate=True):
    """Plots the CDF of the delays. cplen is in microseconds"""
    sorted_dates = sorted(dates)
    datelist = db.fetch_range(sorted_dates, ['date'])
    delays, cdf = lib.empiric_offset_cdf(datelist, bins=bins)

    x = lib.si_prefix(delays, 'mu')
    y = cdf
    ax = continuous(x, y,axes=axes)
    ax.set_xlabel(r'Time ($\mu s$)')
    ax.set_ylabel(r'Cumulative Prob.')

    ylims = ax.get_ylim()
    # Add CP thing
    ax.plot([cplen, cplen], ylims, 'k--')
    txt_str = r' $t_{cp} = $'+ str(cplen) + '$\mu s$' 
    txt_str = r' $t_{cp} - \tau_{max}$'
    ax.text(cplen, 0.02, txt_str, ha='left', va='bottom' )

    if truncate:
        ax.set_xlim([0,1.4*cplen])


    
    save(savename)
    return ax