예제 #1
0
def plot_hist(rtts):
    import hplotting

    gp = hplotting.gp_plotter(loglog=False)

    data = '\n'.join(['%.6f' % rtt for rtt in rtts])

    gp.setup(xlabel='bin width = 1e-6 s')
    gp.cmd('binwidth=1e-6')
    gp.cmd('set boxwidth binwidth')
    gp.cmd('bin(x,width)=width*floor(x/width) + binwidth/2.0')
    gp.cmd("plot '-' using (bin($1,binwidth)):(1.0) smooth freq with boxes\n %s\n e" % (data), flush=True)
    
    gp.quit()
예제 #2
0
def xcplotter(xc, gp=None):
    """Initialize gnuplot and periodically update the graph."""
    if options.no_plot: return

    gp = hplotting.gp_plotter()
    if not gp.gp: return        

    getdata_str = xc.getdata_str
    gp_cmd = gp.cmd
    xc_conf_int = xc.conf_int

    fps = 1.0/options.fps

    # use these to plot axis ranges
    min_x, max_x = (1,options.L)
    min_y, max_y = (1e-6,1e-0)

    # set plot options
    gp.setup(xlabel='log_{10}(lag) [s]', 
             ylabel='log_{10}(autocovariance)', 
             xrange=(min_x, max_x), 
             yrange=(min_y,max_y),
             xtics=[(i*options.delta,i) for i in 10**arange(log10(options.L)+1)],
             )

    ydata = ''

    i=0
    while xc.is_alive():
        i += 1
        if i%10==0:             # plot confidence levels every 10 frames
            ci_level = xc_conf_int()
            #gp.arrow(min_x, ci_level, max_x, ci_level, '3', 8)
            gp.level(ci_level, min_x, max_x)

        # TODO does not terminate cleanly if X11 display cannot be opened
        time.sleep(fps)

        ydata = getdata_str()
        if ydata:
            gp_cmd("plot '-' with points ls 3\n %s\n e"  % ydata, flush=True)


    # calculate confidence interval
    ci_level = xc_conf_int()
    # plot confidence interval level
    #gp.arrow(min_x, ci_level, max_x, ci_level, '3', 8)
    gp.level(ci_level, min_x, max_x)

    # perform fitting for values larger than ci_level
    (d,y0) = xc.fit() # TODO thresh=ci_level
    H = xc.hurst(d)

    ydata = getdata_str()
    if H:
        # plot H linear fit and label it
        gp.label('H=%.2f' % H, 2, 1.2*(y0))      
        gp.arrow(1, y0, xc.L, y0*xc.L**d, '4')

        #xh = 10**((log10(ci_level)-log10(y0))/d)
        #gp.arrow(1, y0, xh, y0*xh**d, '4')

        if ydata:
            gp_cmd("plot '-' with points ls 3\n %s\n e"  % ydata)


    # save plot to EPS
    gp.set_term_eps(options.savefile)


    # we must replot everything to save it to the file
    # plot H linear fit and label it
    gp.label('H=%.2f' % H, 2, 1.2*(y0))      
    #gp.arrow(1, y0, xc.L, y0*xc.L**d, '4')
    gp.level(ci_level, min_x, max_x)
    if ydata:
        gp_cmd("plot '-' with points ls 3\n %s\n e"  % ydata)

    gp.quit()
예제 #3
0
def avplotter(av):
        if not options.plot: return

        gp = hplotting.gp_plotter()
        if not gp.gp: return        

        getdata_str =  av.getdata_str
        gp_cmd = gp.cmd

        fps = 1.0/options.fps



        # use these to plot axis ranges
        min_x = options.M[0]*options.delta
        max_x = options.M[1]*options.delta
        min_y, max_y = (1e-5,1e-0)


        # set plot options
        gp.setup(xlabel='log_{10}(M) [s]', 
                 ylabel='log_{10}(aggregate variance)', 
                 xrange=(min_x, max_x), 
                 yrange=(min_y, max_y),
                 )

        # draw auxiliarry lines
        #y0=1e-0
        #gp.arrow(min_x,y0,    max_x,y0/(max_x/options.delta))
        #gp.arrow(min_x,y0,    y0/0.1,1e-4)


        i = 0
        try:
          while av.is_alive():
            #if not gp.gp: break
            i += 1
            if i%10==0:                              # calculate and plot hurst fit every 10 frames
                (d,y0) = av.fit()
                if y0!=-1:
                    # plot H linear fit and label it
                    gp.arrow(min_x, y0*(min_x/options.delta)**d, max_x, y0*(max_x/options.delta)**d,'2')

            # sleep before redrawing
            time.sleep(fps)

            data = getdata_str()
            if data:
                gp_cmd("plot '-' with points ls 4\n %s\n e\n"  % (data), flush=True)
        except ValueError as e:
            print e # gnuplot error
            return

        # replot with label
        (d,y0) = av.fit()
        if y0!=-1:
            # plot H linear fit and label it
            gp.label('H=%.2f' % (av.hurst(d)), min_x*5, 2*y0*(min_x*5/options.delta)**d, '2')
            gp.arrow(min_x, y0*(min_x/options.delta)**d, max_x, y0*(max_x/options.delta)**d,'2')
        data = getdata_str()
        if data:
            gp_cmd("plot '-' with points ls 4\n %s\n e\n"  % (data), flush=True)


        # save plot to EPS
        gp.set_term_eps(options.savefile)
        # we must replot everything to save it to the file
        (d,y0) = av.fit()
        if y0!=-1:
            # plot H linear fit and label it
            gp.label('H=%.2f' % (av.hurst(d)), min_x*5, 2*y0*(min_x*5/options.delta)**d, '2')
            gp.arrow(min_x, y0*(min_x/options.delta)**d, max_x, y0*(max_x/options.delta)**d,'2')


        data = getdata_str()
        gp_cmd("plot '-' with points ls 4\n %s\n e\n"  % (data), flush=True)
        gp.quit()