Esempio n. 1
1
def show(sample_size):
    global session
    global scatter_plot
    global source
    global pie_chart_source
    global line_chart_source
    global slider
    DB.__init__(sample_size)
    min_time = DB.min_time()
    max_time = DB.max_time()
    print min_time
    print min_time
    xs, ys, color, time = DB.get_current()
    xs = [xs[i] for i,v in enumerate(time) if time[i] == min_time]
    ys = [ys[i] for i,v in enumerate(time) if time[i] == min_time]
    color = [color[i] for i,v in enumerate(time) if time[i] == min_time]

    time_dict = Counter(time)
    pie_chart_source = ColumnDataSource(data=ChartMath.compute_color_distribution('x', 'y', 'color', color))
    line_chart_source = ColumnDataSource(data=dict(x=[key for key in time_dict], y=[time_dict[key] for key in time_dict]))
    source = ColumnDataSource(data=dict(x=xs, y=ys, color=color))

    scatter_plot = Figure(plot_height=800,
                          plot_width=1200,
                          title="Plot of Voters",
                          tools="pan, reset, resize, save, wheel_zoom",
                          )

    scatter_plot.circle('x', 'y', color='color', source=source, line_width=0, line_alpha=0.001, fill_alpha=0.5, size=15)
    scatter_plot.patches('x', 'y', source=state_source, fill_alpha=0.1, line_width=3, line_alpha=1)

    scatter_plot.x_range.on_change('end', update_coordinates)
    line_chart = Figure(title="Distribution over Time", plot_width=350, plot_height=350)
    line_chart.line(x='x', y='y', source=line_chart_source)
    pie_chart_plot = Figure(plot_height=350,
                            plot_width=350,
                            title="Voter Distribution",
                            x_range=(-1, 1),
                            y_range=(-1, 1))
    pie_chart_plot.wedge(x=0, y=0, source=pie_chart_source, radius=1, start_angle="x", end_angle="y", color="color")
    slider = Slider(start=min_time, end=max_time, value=min_time, step=1, title="Time")

    slider.on_change('value', update_coordinates)
    h = hplot(scatter_plot, vplot(pie_chart_plot, line_chart))
    vplot(slider, h, width=1600, height=1800)
    session = push_session(curdoc())
    session.show()
    #script = autoload_server(scatter_plot, session_id=session.id)
    session.loop_until_closed()
def run(input_files, output_files):

    # Read reaction sequences
    sequs = gazelib.io.load_json(input_files[0])

    # Collect figures here.
    figs = []

    for sequence in sequs:

        srts = []

        # Trials
        for trial in sequence:
            if trial['heuristic_saccade_validity']:
                srts.append(trial['srt'])
            else:
                srts.append(0)

        # To milliseconds
        srts = list(map(to_milliseconds, srts))

        d = {
            'SRT': srts,
            'Trial': list(range(1,13))
        }
        p = Bar(d, label='Trial', values='SRT', color='black')
        figs.append(p)

    # Visualization with bokeh. Combine figures in vertical layout.
    p = plotting.vplot(*figs)
    plotting.output_file(output_files[0],
                         'Saccadic reaction time variability')
    plotting.save(p)
def make_washmap_map_tools_linked():
    data = get_data_with_countries(wat_stats, san_stats)
    source = ColumnDataSource(data)
    wat_map = construct_water_map_tools(source)
    wat_text = construct_water_text(source)
    wat_key = construct_key(WATER_COLOR_RANGE)
    return hplot(vplot(wat_map), vplot(wat_text, wat_key))
def make_washmap_map_tools_linked():
    data = get_data_with_countries(wat_stats, san_stats)
    source = ColumnDataSource(data)
    wat_map = construct_water_map_tools(source)
    wat_text = construct_water_text(source)
    wat_key = construct_key(WATER_COLOR_RANGE)
    return hplot(vplot(wat_map), vplot(wat_text, wat_key))
    def __init__(self, title, legends, n_images_train=0, n_images_test=0, n_cols_images=3, axisx="Epochs",
                 axisy="Values", line_width=4, alpha=0.8, line_dash=[4, 4], plot_width=800, plot_height=400):

        # Save some parameters
        self.n_lines_plot = len(legends)
        self.n_images_train = n_images_train
        self.n_images_test = n_images_test

        # prepare output to server
        output_server(title)
        cursession().publish()

        # Create the figure plot
        if self.n_lines_plot > 0:
            p_plot, self.data_plot = self.create_figure_plot(title, legends, axisx=axisx, axisy=axisy,
                                                             line_width=line_width, alpha=alpha, line_dash=line_dash,
                                                             plot_width=plot_width, plot_height=plot_height)

        if n_images_train > 0:
            # Create black images as initialization
            img = np.zeros((64, 256, 3))
            img_batch = []
            for i in xrange(n_images_train):
                img_batch.append(img)

            # Create the training image grid
            p_images_train, self.data_img_train = self.create_grid_images(img_batch, name='img_train', n_cols=n_cols_images)

        if n_images_test > 0:
            # Create black images as initialization
            img = np.zeros((64, 256, 3))
            img_batch = []
            for i in xrange(n_images_test):
                img_batch.append(img)

            # Create the testing image grid
            p_images_test, self.data_img_test = self.create_grid_images(img_batch, name='img_test', n_cols=n_cols_images)

        # Create a vertical grid with the plot and the train and test images
        if self.n_lines_plot > 0 and n_images_train > 0 and n_images_test > 0:
            p = vplot(p_plot, p_images_train, p_images_test)
        elif self.n_lines_plot > 0 and n_images_train > 0 and n_images_test <= 0:
            p = vplot(p_plot, p_images_train)
        else:
            print 'ERROR: Not implemented combination. Please, do it!'

        # Show the plot
        show(p)
Esempio n. 6
0
def generate_plots(execs,
                   plot_list=('cpu_bars', 'gpu_bars', 'user_total_memusage')):
    monitor_methods = list()
    if any('gpu' in pltname for pltname in plot_list):
        monitor_methods.append('gpus_mon')
    if any('cpu' in pltname for pltname in plot_list):
        monitor_methods.append('cpus_mon')

    _hplots = list()
    panels = list()
    monitors = list()
    change_streams = list()
    for name, ex in execs.items():
        changes = ChangeStream(source_fun=update_notebook_source)
        mon = RessourceMonitor(changes, async_exec=ex[0], normal_exec=ex[1])
        plot_gen = BokehPlots(changes, async_exec=ex[0], normal_exec=ex[1])
        plt = vplot(*[getattr(plot_gen, plt).__call__()
                      for plt in plot_list])

        hostname = ex[1](['hostname'], stdout=PIPE).communicate()[0].decode().strip('\r\n ')
        panels.append(Panel(title=hostname, child=plt))
        _hplots.append(plt)
        for mon_method in monitor_methods:
            monitors.append(getattr(mon, mon_method))

        change_streams.append(changes)
    tabs = Tabs(tabs=panels)

    return hplot(tabs), monitors, change_streams
def make_washmap_all():
    data = get_data_with_countries(wat_stats, san_stats)

    source = ColumnDataSource(data)
    source.selected = [30]
    line_data = get_line_data('Morocco')
    line_source = ColumnDataSource(line_data)

    wat_map = construct_water_map_tools(source)
    wat_line = construct_water_line(line_source)
    wat_text = construct_water_text(source)
    wat_key = construct_key(WATER_COLOR_RANGE)
    san_map = construct_san_map_tools(source)
    san_line = construct_san_line(line_source)
    san_text = construct_san_text(source)
    san_key = construct_key(SANITATION_COLOR_RANGE)

    tabs = Tabs(tabs=[
        Panel(title="Water",
              child=layout_components(wat_map, wat_line, wat_text, wat_key)),
        Panel(title="Sanitation",
              child=layout_components(san_map, san_line, san_text, san_key))
    ])
    year = Slider(title="Year",
                  name='year',
                  value=1990,
                  start=1990,
                  end=2012,
                  step=1)

    return vplot(tabs, year)
def plot(output_directory, normalized_counts, chromosome, cell_types):
    bp.output_file(output_directory + "/" + chromosome + ".html", mode="cdn")
    plots = []

    summary = plot_summary(normalized_counts, chromosome)
    if summary:
        plots.append(summary)
    else:
        # if summary can't be plotted, then rest probably can't be plotted either,
        # so return without even saving the file (the file is never created on disk if not saved)
        return
    for cell_type in cell_types:
        logging.debug(" - plotting %s", cell_type)

        bin_number = [] 
        count = [] 
        
        condition = "(file_key == 0) & (chromosome == '%s') & (cell_type == '%s')" % (chromosome, cell_type)

        for row in normalized_counts.where(condition):
            bin_number.append(row["bin_number"])
            count.append(row["count"])

        plot = bp.figure()
        plot.title = "%s counts per bin" % cell_type
        plot.scatter(bin_number, count)
        plots.append(plot)
    bp.save(bp.vplot(*plots))
Esempio n. 9
0
def main(options, args):

    logger = log.get_logger("ginga", options=options)

    # create a new plot with default tools, using figure
    fig = figure(x_range=[0, 600],
                 y_range=[0, 600],
                 plot_width=600,
                 plot_height=600,
                 toolbar_location=None)

    viewer = ib.CanvasView(logger)
    viewer.set_figure(fig)

    def load_file(path):
        image = AstroImage(logger)
        image.load_file(path)
        viewer.set_image(image)

    def load_file_cb(attr_name, old_val, new_val):
        #print(attr_name, old_val, new_val)
        load_file(new_val)

    # add a entry widget and configure with the call back
    dstdir = options.indir
    path_w = TextInput(value=dstdir, title="File:")
    path_w.on_change('value', load_file_cb)

    if len(args) > 0:
        load_file(args[0])

    # put the path widget and viewer in a layout and add to the document
    curdoc().add_root(vplot(fig, path_w))
Esempio n. 10
0
 def _make_figures(self,ep,trainerr,metvals):
     self._datasources = []
     figures = []
     fig = figure(title='Total Training Cost',x_axis_label='Epoch',y_axis_label='Cost')
     fig.line([ep],[trainerr],name='plot')
     ds = fig.select(dict(name='plot'))[0].data_source
     self._datasources.append(ds)
     if self._plotmetricmean:
         figures.append(fig)
         fig = figure(title='Metric Mean',x_axis_label='Epoch',y_axis_label='Mean')
         fig.line([ep],[np.nanmean(metvals)],name='plot')
         ds = fig.select(dict(name='plot'))[0].data_source
         self._datasources.append(ds)
         figures.append(fig)
     for mv,(mk,m) in zip(metvals,self.metrics):
         if m.metric in xnn.metrics.metric_names:
             name = xnn.metrics.metric_names[m.metric]
         else:
             name = m.metric.__name__
         fig = figure(title=mk,x_axis_label='Epoch',y_axis_label=name)
         fig.line([ep],[mv],name='plot')
         ds = fig.select(dict(name='plot'))[0].data_source
         self._datasources.append(ds)
         figures.append(fig)
     allfigs = vplot(*figures)
     push()
def plot(output_directory, normalized_counts, chromosome, cell_types):
    bp.output_file(output_directory + "/" + chromosome + ".html", mode="cdn")
    plots = []

    summary = plot_summary(normalized_counts, chromosome)
    if summary:
        plots.append(summary)
    else:
        # if summary can't be plotted, then rest probably can't be plotted either,
        # so return without even saving the file (the file is never created on disk if not saved)
        return
    for cell_type in cell_types:
        logging.debug(" - plotting %s", cell_type)

        bin_number = [] 
        count = [] 
        
        condition = "(file_key == 0) & (chromosome == '%s') & (cell_type == '%s')" % (chromosome, cell_type)

        for row in normalized_counts.where(condition):
            bin_number.append(row["bin_number"])
            count.append(row["count"])

        plot = bp.figure()
        plot.title = "%s counts per bin" % cell_type
        plot.scatter(bin_number, count)
        plots.append(plot)
    bp.save(bp.vplot(*plots))
Esempio n. 12
0
def _draw_multiple_line_plot(filename, title, X, y, colors, legend, line_dash, line_width, x_axis_type, x_axis_label, y_axis_label, y_start=0, y_end=10, width=800, height=400):
    
    #output_file(filename, title=title)
    p1 = figure(x_axis_type = x_axis_type, plot_width=width, plot_height=height, y_range=(y_start, y_end))   

    for i in range(len(y)):
        p1.line(X[i], y[i], color=colors[i], legend=legend[i], line_dash=line_dash[i], line_width=line_width[i])
    #p1.multi_line(X, y, color=colors, legend=legend, line_dash=line_dash, line_width=line_width)
    # p1.multi_line(xs=X,
    #             ys=y,
    #             line_color=colors,
    #             line_width=5)
    p1.title = title
    #p1.grid.grid_line_color='Black'
    #p.ygrid[0].grid_line_alpha=0.5
    p1.legend.orientation = "bottom_left"
    p1.grid.grid_line_alpha=0.75
    p1.xaxis.axis_label = x_axis_label
    p1.yaxis.axis_label = y_axis_label
    p1.ygrid.band_fill_color="olive"
    p1.ygrid.band_fill_alpha = 0.25
    p1.ygrid.minor_grid_line_color = 'navy'
    p1.ygrid.minor_grid_line_alpha = 0.1

    save(vplot(p1), filename=filename, title=title)  
Esempio n. 13
0
def notebook(*tunnels):
    from bokeh.io import show
    execs = dict()
    if tunnels:
        for tunnel in tunnels:
            t_args = re.findall('([\'"]([^"\']+)["\'])|([^ ]+)', tunnel)
            t_args = [a[-1] if a[-1] else a[-1] for a in t_args]
            t_args = [a.strip(' ') for a in t_args]
            execs['_'.join(t_args)] = make_ssh_subprocess(*t_args)
    else:
        execs['localhost'] = async_subprocess, Popen

    _hplots = list()
    monitors = list()
    change_streams = list()
    for ex in execs.values():
        changes = ChangeStream(source_fun=update_notebook_source)
        mon = RessourceMonitor(changes, async_exec=ex[0], normal_exec=ex[1])
        plot_gen = BokehPlots(changes, async_exec=ex[0], normal_exec=ex[1])
        _hplots.append(
            vplot(plot_gen.cpu_bars(False), plot_gen.gpu_bars(),
                  plot_gen.user_total_memusage()))
        monitors.append(mon)
        change_streams.append(changes)
    plots = hplot(*_hplots)
    show(plots)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(
        asyncio.gather(*(mon.gpus_mon(loop=loop) for mon in monitors),
                       *(mon.cpus_mon() for mon in monitors),
                       *(changes.start() for changes in change_streams)))
def make_washmap_all():
    data = get_data_with_countries(wat_stats, san_stats)

    source = ColumnDataSource(data)
    source.selected = [30]
    line_data = get_line_data("Morocco")
    line_source = ColumnDataSource(line_data)

    wat_map = construct_water_map_tools(source)
    wat_line = construct_water_line(line_source)
    wat_text = construct_water_text(source)
    wat_key = construct_key(WATER_COLOR_RANGE)
    san_map = construct_san_map_tools(source)
    san_line = construct_san_line(line_source)
    san_text = construct_san_text(source)
    san_key = construct_key(SANITATION_COLOR_RANGE)

    tabs = Tabs(
        tabs=[
            Panel(title="Water", child=layout_components(wat_map, wat_line, wat_text, wat_key)),
            Panel(title="Sanitation", child=layout_components(san_map, san_line, san_text, san_key)),
        ]
    )
    year = Slider(title="Year", name="year", value=1990, start=1990, end=2012, step=1)

    return vplot(tabs, year)
Esempio n. 15
0
    def __init__(self, addr=None, interval=1000.00, loop=None):
        if addr is None:
            scheduler = default_executor().scheduler
            if isinstance(scheduler, rpc):
                addr = (scheduler.ip, 9786)
            elif isinstance(scheduler, Scheduler):
                addr = ('127.0.0.1', scheduler.services['http'].port)
        self.addr = addr
        self.interval = interval

        self.display_notebook = False

        if is_kernel() and not curstate().notebook:
            output_notebook()
            assert curstate().notebook

        self.task_source, self.task_table = task_table_plot()
        self.worker_source, self.worker_table = worker_table_plot()

        self.output = vplot(self.worker_table, self.task_table)

        self.client = AsyncHTTPClient()

        self.loop = loop or IOLoop.current()
        self.loop.add_callback(self.update)
        self._pc = PeriodicCallback(self.update, self.interval, io_loop=self.loop)
        self._pc.start()
Esempio n. 16
0
def worker_table_plot(width=600, height="auto", **kwargs):
    """ Column data source and plot for host table """
    names = ['workers', 'cpu', 'memory-percent', 'memory', 'cores', 'processes',
             'processing', 'latency', 'last-seen', 'disk-read', 'disk-write',
             'network-send', 'network-recv']
    source = ColumnDataSource({k: [] for k in names})

    columns = {name: TableColumn(field=name, title=name) for name in names}

    slow_names = ['workers', 'cores', 'processes', 'memory',
                  'latency', 'last-seen']
    slow = DataTable(source=source, columns=[columns[n] for n in slow_names],
                     width=width, height=height, **kwargs)
    slow.columns[3].formatter = NumberFormatter(format='0.0 b')
    slow.columns[4].formatter = NumberFormatter(format='0.00000')
    slow.columns[5].formatter = NumberFormatter(format='0.000')

    fast_names = ['workers', 'cpu', 'memory-percent', 'processing',
            'disk-read', 'disk-write', 'network-send', 'network-recv']
    fast = DataTable(source=source, columns=[columns[n] for n in fast_names],
                     width=width, height=height, **kwargs)
    fast.columns[1].formatter = NumberFormatter(format='0.0 %')
    fast.columns[2].formatter = NumberFormatter(format='0.0 %')
    fast.columns[4].formatter = NumberFormatter(format='0 b')
    fast.columns[5].formatter = NumberFormatter(format='0 b')
    fast.columns[6].formatter = NumberFormatter(format='0 b')
    fast.columns[7].formatter = NumberFormatter(format='0 b')

    table = vplot(slow, fast)
    return source, table
def run(input_files, output_files):

    # Read reaction sequences
    stats = gazelib.io.load_json(input_files[0])

    # Collect figures here.
    figs = []


    # Sequence completeness distribution
    d = {
        'num saccades captured': stats['total']['completeness'],
        'sequences': [1] * len(stats['total']['completeness'])
    }
    p = Bar(d, agg='count', label='num saccades captured', values='sequences', color='black')
    figs.append(p)


    # Saccademodel MSE distribution
    mses = stats['total']['all_mses']
    d = { 'MSE': list(filter(lambda x: x < 0.1, mses)) }
    p = Histogram(d, bins=40, values='MSE', color='black')
    figs.append(p)


    # Visualization with bokeh. Combine figures in vertical layout.
    p = plotting.vplot(*figs)
    plotting.output_file(output_files[0],
                         'Saccadic reaction time variability')
    plotting.save(p)
Esempio n. 18
0
def _create_grid_plot_of_trends(df, X, col_list, filename):

    width  = 600
    height = 400
        
    color_palette = [ 'Black', 'Red', 'Purple', 'Green', 'Brown', 'Yellow', 'Cyan', 'Blue', 'Orange', 'Pink']
    i = 0
    #2 columns, so number of rows is total /2 
    row_index = 0
    row_list = []
    row = []
    for col in col_list[1:]: #skip the date column
        # create a new plot
        s1 = figure(x_axis_type = 'datetime', width=width, plot_height=height, title=col + ' trend')
        #seasonal decompae to extract seasonal trends
        decomposition = seasonal_decompose(np.array(df[col]), model='additive', freq=15)  
        s1.line(X, decomposition.trend, color=color_palette[i % len(color_palette)], alpha=0.5, line_width=2)

        row.append(s1)
        if len(row) == 2:
            row_copy = copy.deepcopy(row)
            row_list.append(row_copy)
            row = []
            i = 0
        i += 1
        

    # put all the plots in a grid layout
    p = gridplot(row_list)

    save(vplot(p), filename=filename, title='trends')  
Esempio n. 19
0
 def get_plot(self, mode="v"):
     if not (mode is 'v' or mode is 'h'):
         raise MeteoStation.InvalidPlotArgument()
     if mode is 'v':
         return vplot(*self.figs)
     else:
         return hplot(*self.figs)
Esempio n. 20
0
def bokeh2(X):
    Y = de_mean_matrix(X)    

    TOOLS="resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave,box_select"
    
    hover = HoverTool(
        tooltips=[
            ("index", "$index"),
            ("(x,y)", "($x, $y)"),
            ("desc", "@desc"),
        ]
    )

    bplt.output_file("data.html", title="Rescaling")
    
    s1 = bplt.figure(width=500, plot_height=250, title="Data", tools=[hover, TOOLS])
    s1.scatter(X[:,0].A1, X[:,1].A1, marker="circle",
              line_color="#6666ee", fill_color="#ee6666",
              fill_alpha=0.5, size=12)
    
    s2 = bplt.figure(width=500, plot_height=250, title="De-meaned", tools=TOOLS)
    s2.scatter(Y[:,0].A1, Y[:,1].A1, marker="circle",
              line_color="#6666ee", fill_color="#ee6666",
              fill_alpha=0.5, size=12)
    
    # put all the plots in a VBox
    p = bplt.vplot(s1, s2)
    
    # show the results
    bplt.show(p)
Esempio n. 21
0
def notebook(*tunnels):
    from bokeh.io import show
    execs = dict()
    if tunnels:
        for tunnel in tunnels:
            t_args = re.findall('([\'"]([^"\']+)["\'])|([^ ]+)', tunnel)
            t_args = [a[-1] if a[-1] else a[-1] for a in t_args]
            t_args = [a.strip(' ') for a in t_args]
            execs['_'.join(t_args)] = make_ssh_subprocess(*t_args)
    else:
        execs['localhost'] = async_subprocess, Popen

    _hplots = list()
    monitors = list()
    change_streams = list()
    for ex in execs.values():
        changes = ChangeStream(source_fun=update_notebook_source)
        mon = RessourceMonitor(changes, async_exec=ex[0], normal_exec=ex[1])
        plot_gen = BokehPlots(changes, async_exec=ex[0], normal_exec=ex[1])
        _hplots.append(vplot(plot_gen.cpu_bars(False), plot_gen.gpu_bars(),
                             plot_gen.user_total_memusage()))
        monitors.append(mon)
        change_streams.append(changes)
    plots = hplot(*_hplots)
    show(plots)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(asyncio.gather(
        *(mon.gpus_mon(loop=loop) for mon in monitors),
        *(mon.cpus_mon() for mon in monitors),
        *(changes.start() for changes in change_streams)
    ))
    def chart_results(self):
        portfolios = self.db.get_all_portfolios()
        
        portfolio_results = {
            'portfolios': portfolios,
            'overview'   : {
                'ytd'   : self.average_performance('difference_ytd', portfolios),
                '1year' : self.average_performance('difference_1year', portfolios)
            }
        }
        portfolio_results['overview']['results_ytd'] = self.outperform(portfolio_results['overview']['ytd'])
        portfolio_results['overview']['results_1year'] = self.outperform(portfolio_results['overview']['1year'])


        num_points = len(portfolios)
        pprint(num_points)
        now = time.time()
        dates =[]
        moneyky_perf=[]
        portfolio_perf=[]

        #Form the lists
        for each in portfolios:
            dates.append(each['date'])
            moneyky_perf.append(float(each['difference_ytd']))
            portfolio_perf.append(float(each['difference_1year']))
        TOOLS = "reset,save"
        r = figure(x_axis_type = "datetime", tools=TOOLS, plot_width=800, plot_height=400)
        r.line(dates, portfolio_perf, legend='Monkey ytd', color="firebrick", alpha=0.8, line_width=4)
        r.line(dates, moneyky_perf,  legend='Monkey 1 Year', color="navy", alpha=0.8, line_width=4)
        r.title = "Moneyky vs Benchmark Performance"

        r.grid.grid_line_alpha=100
        return (vplot(r)), portfolio_results  # return the plot
Esempio n. 23
0
	def get_plot(self, mode="v"):
		if not(mode is 'v' or mode is 'h'):
			raise MeteoStation.InvalidPlotArgument()
		if mode is 'v':
			return vplot(*self.figs)
		else:
			return hplot(*self.figs)
Esempio n. 24
0
    def __init__(self, addr=None, interval=1000.00, loop=None):
        if addr is None:
            scheduler = default_executor().scheduler
            if isinstance(scheduler, rpc):
                addr = (scheduler.ip, 9786)
            elif isinstance(scheduler, Scheduler):
                addr = ('127.0.0.1', scheduler.services['http'].port)
        self.addr = addr
        self.interval = interval

        self.display_notebook = False

        if is_kernel() and not curstate().notebook:
            output_notebook()
            assert curstate().notebook

        self.task_source, self.task_table = task_table_plot()
        self.worker_source, self.worker_table = worker_table_plot()

        self.output = vplot(self.worker_table, self.task_table)

        self.client = AsyncHTTPClient()

        self.loop = loop or IOLoop.current()
        self.loop.add_callback(self.update)
        self._pc = PeriodicCallback(self.update, self.interval, io_loop=self.loop)
        self._pc.start()
Esempio n. 25
0
def main(options, args):
    
    logger = log.get_logger("ginga", options=options)

    # create a new plot with default tools, using figure
    fig = figure(x_range=[0,600], y_range=[0,600], plot_width=600, plot_height=600,
                 toolbar_location=None)

    viewer = ib.CanvasView(logger)
    viewer.set_figure(fig)

    def load_file(path):
        image = AstroImage(logger)
        image.load_file(path)
        viewer.set_image(image)

    def load_file_cb(attr_name, old_val, new_val):
        #print(attr_name, old_val, new_val)
        load_file(new_val)

    # add a entry widget and configure with the call back
    dstdir = options.indir
    path_w = TextInput(value=dstdir, title="File:")
    path_w.on_change('value', load_file_cb)

    if len(args) > 0:
        load_file(args[0])

    # put the path widget and viewer in a layout and add to the document
    curdoc().add_root(vplot(fig, path_w))
Esempio n. 26
0
def visualize_data(data_output_file):
    from bokeh.plotting import figure, output_file, save, vplot
    from bokeh.models import ColumnDataSource, FactorRange

    plots = []

    # output to static HTML file
    output_file(data_output_file, title='Eye Tracking Data', mode='cdn')

    for file_name, file_data in data.iteritems():
        # prepare the data
        line_types = [line_data[0] for line_data in file_data]
        #line_types_top = [line_data[0] + '2.0' for line_data in file_data]
        #line_types_bot = [line_data[0] + '1.0' for line_data in file_data]
        times = [line_data[1] for line_data in file_data]
        start_times = [line_data[2] for line_data in file_data]
        end_times = [line_data[3] for line_data in file_data]
        descs = [line_data[4] for line_data in file_data]

        #x0 = [0 for type_ in line_types]

        '''source = ColumnDataSource({
            'time': times,
            'start': start_times,
            'end': end_times,
            'line_types_top': line_types_top,
            'line_types_bot': line_types_bot,
        })'''

        source = ColumnDataSource({
            'x': [(t1 + t2)/2 for t1, t2 in zip(start_times, end_times)],
            'y': line_types,
            'width': times,
            'height': [0.7 for _ in line_types],
            'fill_color': ['red' if 'Incorrect' in desc \
                    else 'green' for desc in descs]
        })

        # create a new plot
        plot = figure(
           tools='pan,reset,save',
           title=file_name, y_range=FactorRange(factors=line_types[::-1]),
           x_range=[0, sum(times)],
           x_axis_label='Time (ms)', y_axis_label='Line Type'
        )

        plot.rect(x='x', y='y', width='width', height='height', \
            fill_color='fill_color', source=source)

        #plot.quad(left='start', right='end', \
        #    top='line_types_top', bottom='line_types_bot', source=source)
    
        # add some renderers
        #plot.segment(x0, line_types, times, line_types, \
        #    line_width=2, line_color="green")

        plots.append(plot)

    # show the results
    save(vplot(*plots))
def make_interactive(plot):
    plot = add_legend(plot)
    
    for year in years:
        fertility = fertility_df[year]
        fertility.name = 'fertility'
        life = life_expectancy_df[year]
        life.name = 'life'
        population = population_df_size[year]
        population.name = 'population'
        new_df = pd.concat([fertility, life, population, region_color], axis=1)
        sources['_' + str(year)] = ColumnDataSource(new_df)

    dictionary_of_sources = dict(zip([x for x in years], ['_%s' % x for x in years]))
    js_source_array = str(dictionary_of_sources).replace("'", "")

    # Add the slider
    code = """
        var year = slider.get('value'),
            sources = %s,
            new_source_data = sources[year].get('data');
        renderer_source.set('data', new_source_data);
        renderer_source.trigger('change');
        text_source.set('data', {'year': [String(year)]});
        text_source.trigger('change');
    """ % js_source_array

    callback = CustomJS(args=sources, code=code)
    slider = Slider(start=years[0], end=years[-1], value=1, step=1, title="Year", callback=callback)
    callback.args["slider"] = slider
    callback.args["renderer_source"] = renderer_source
    callback.args["text_source"] = text_source

    
    return vplot(plot, slider)
Esempio n. 28
0
	def insertPlot(self, plotSets):
		plotSets = [wrapper.plot for wrapper in plotSets]
		layout   = vplot( *plotSets )
		# output_file("les_mis.html") ?????????????????
		# show(layout)
		for plot in plotSets:
			plot.toolbar_location = None
		return layout
def plot_summaries(output_directory, normalized_counts, chromosomes):
    bp.output_file(output_directory + "/summary.html", mode="cdn")
    plots = []
    for chromosome in chromosomes:
        plot = plot_summary(normalized_counts, chromosome)
        if plot:
            plots.append(plot)
    bp.save(bp.vplot(*plots))
def plot_summaries(output_directory, normalized_counts, chromosomes):
    bp.output_file(output_directory + "/summary.html", mode="cdn")
    plots = []
    for chromosome in chromosomes:
        plot = plot_summary(normalized_counts, chromosome)
        if plot:
            plots.append(plot)
    bp.save(bp.vplot(*plots))
Esempio n. 31
0
 def insertPlot(self, plotSets):
     plotSets = [wrapper.plot for wrapper in plotSets]
     layout = vplot(*plotSets)
     # output_file("les_mis.html") ?????????????????
     # show(layout)
     for plot in plotSets:
         plot.toolbar_location = None
     return layout
def make_washmap_map_tools_linked_tabbed():
    data = get_data_with_countries(wat_stats, san_stats)
    source = ColumnDataSource(data)
    source.selected = [30]
    wat_map = construct_water_map_tools(source)
    wat_text = construct_water_text(source)
    wat_key = construct_key(WATER_COLOR_RANGE)
    san_map = construct_san_map_tools(source)
    san_text = construct_san_text(source)
    san_key = construct_key(SANITATION_COLOR_RANGE)

    tabs = Tabs(
        tabs=[
            Panel(title="Water", child=hplot(vplot(wat_map), vplot(wat_text, wat_key))),
            Panel(title="Sanitation", child=hplot(vplot(san_map), vplot(san_text, san_key))),
        ]
    )
    return vplot(tabs)
def make_washmap_map_tools_linked_tabbed():
    data = get_data_with_countries(wat_stats, san_stats)
    source = ColumnDataSource(data)
    source.selected = [30]
    wat_map = construct_water_map_tools(source)
    wat_text = construct_water_text(source)
    wat_key = construct_key(WATER_COLOR_RANGE)
    san_map = construct_san_map_tools(source)
    san_text = construct_san_text(source)
    san_key = construct_key(SANITATION_COLOR_RANGE)

    tabs = Tabs(tabs=[
        Panel(title="Water",
              child=hplot(vplot(wat_map), vplot(wat_text, wat_key))),
        Panel(title="Sanitation",
              child=hplot(vplot(san_map), vplot(san_text, san_key)))
    ])
    return vplot(tabs)
Esempio n. 34
0
def create_simple_layout(obj):
    # TODO: Seems that DateRangeSlider is broken on latest release. It'd be
    #       nice to add it when issue is fixed
    # start = datetime.date(2010, 1, 1)#'2010-01-01'
    # end = datetime.date(2015, 1, 1)#'2015-01-01'
    # obj.dr = DateRangeSlider(
    #     title="Period:", name="period", value=(start, end),
    #     bounds=(start, end), range=(dict(days=1), None)
    # )
    # Get the widget for all available plugins and add them

    interval_plugins = {pl.name: getattr(obj, pl.name)
                        for pl in obj._interval_plugins}
    names = dict(
        js_list_of_sources=str({k: k for k in interval_plugins.keys()}).replace("'", "")
    )
    code = callbacks.window_selector % names
    objs = dict(interval_plugins)
    callback = Callback(args=objs, code=code)
    obj.window_selector.callback = callback
    callback.args['interval_selector'] = obj.window_selector

    # configure button to open pump and dump detection (Poulson Algorithm)
    code = callbacks.btn_detect_pumps % names
    callback = Callback(args=objs, code=code)
    obj.btn_detect_pumps.callback = callback

    main_view = plotting.hplot(
        plotting.vplot(
            obj.ts_filters_plot,
            obj.main_plot,
            # obj.cp_plot,
            # obj.trends_plot
        ),
    )

    # add spams table to spams tab
    obj.spam_tab.child = plotting.hplot(obj.spam_table)

    # create
    obj.vpeaks = plotting.vplot(obj.PEAKS)
    obj.children = [plotting.vplot(
        main_view,
    )]
Esempio n. 35
0
def acc_loss_visual(history, result_path, script_name, file_time_global):
    """
    Plot accuracy and loss 
    """
    acc_arr = np.array(history['acc'], dtype=float)
    loss_arr = np.array(history['loss'], dtype=float)
    val_acc_arr = np.array(history['val_acc'], dtype=float)
    val_loss_arr = np.array(history['val_loss'], dtype=float)
    output_file(
        os.path.join(
            result_path,
            "legends_" + script_name + "_" + file_time_global + ".html"))
    p1 = figure()
    p1.title = "Training and Cross validation accuracy"
    p1.xaxis.axis_label = 'Iterations'
    p1.yaxis.axis_label = 'Accuracy'
    p1.circle(range(0, len(acc_arr)),
              acc_arr,
              color="green",
              legend="Train_Acc")
    p1.line(range(0, len(acc_arr)),
            acc_arr,
            line_color="green",
            legend="Train_Acc")
    p1.circle(range(0, len(val_acc_arr)),
              val_acc_arr,
              color="orange",
              legend="Val_Acc")
    p1.line(range(0, len(val_acc_arr)),
            val_acc_arr,
            line_color="orange",
            legend="Val_Acc")
    p2 = figure()
    p2.title = "Training and Cross validation loss_error"
    p2.xaxis.axis_label = 'Iterations'
    p2.yaxis.axis_label = 'Loss_error'
    p2.circle(range(0, len(loss_arr)),
              loss_arr,
              color="green",
              legend="Train_loss")
    p2.line(range(0, len(loss_arr)),
            loss_arr,
            line_color="green",
            legend="Train_loss")
    p2.circle(range(0, len(val_loss_arr)),
              val_loss_arr,
              color="orange",
              legend="Val_loss")
    p2.line(range(0, len(val_loss_arr)),
            val_loss_arr,
            line_color="orange",
            legend="Val_loss")
    p = vplot(p1, p2)
    show(p)
Esempio n. 36
0
def create_layout(obj):
    # Get the widget for all available plugins and add them

    interval_plugins = {pl.name: getattr(obj, pl.name)
                        for pl in obj._interval_plugins}
    names = dict(
        js_list_of_sources=str({k: k for k in interval_plugins.keys()}).replace("'", "")
    )
    code = callbacks.window_selector % names
    objs = dict(interval_plugins)
    callback = Callback(args=objs, code=code)
    obj.window_selector.callback = callback
    callback.args['interval_selector'] = obj.window_selector


    # configure button to open pump and dump detection (Poulson Algorithm)
    code = callbacks.btn_detect_pumps % names
    callback = Callback(args=objs, code=code)
    obj.btn_detect_pumps.callback = callback

    # add all elements of the main dashboard
    main_view = plotting.hplot(
        plotting.vplot(
            obj.ts_filters_plot, obj.main_plot,
        ),
    )

    # add spams table to spams tab
    obj.spam_tab.child = plotting.hplot(obj.spam_table)

    # create
    obj.vpeaks = plotting.vplot(obj.PEAKS)
    # vsteinberg = plotting.vplot(obj.TICKS_IN_ROW)
    obj.children = [plotting.vplot(
        # obj.symbol,
        # obj.tabs,
        main_view,
        # vpeaks, # add peaks plugin dialog view
        # vsteinberg,
        # obj.dialog_loading,
    )]
Esempio n. 37
0
def pages_timeseries(response):
    parse_datetime = lambda x: datetime.datetime.strptime(x, "%Y-%m-%dT%H:%M:%S.%f")
    parsed_dates = [parse_datetime(x[1]) for x in response]
    dates = sorted(parsed_dates)
    plot = figure(plot_width=584, x_axis_type="datetime", x_axis_label="Dates",
            y_axis_label="Number Fetched")
    plot.line(x=dates, y=range(len(dates)))

    button = Button(label="Press Me")

    session = push_session(curdoc())
    script = autoload_server(vplot(plot, button), session_id=session.id)
    return script
Esempio n. 38
0
def create_grph(lst, df, stock):
    TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
    #Just figure out how to divide the graph to make it nicer
    fig_list = []
    if u'Closing' in lst:
        output_file("./templates/stock.html", title=stock)
        a = figure(x_axis_type="datetime", tools=TOOLS)
        a.line(df['Date'],
               df['Closing'],
               color='#1F78B4',
               legend='Closing Prices')
        a.title = "%s Closing Prices" % (stock)
        a.grid.grid_line_alpha = 0.3
        fig_list.append('a')

    if u'Adjusted' in lst:
        output_file("./templates/stock.html", title=stock)
        b = figure(x_axis_type="datetime", tools=TOOLS)
        b.line(df['Date'],
               df['Adj Closing'],
               color='#FF0000',
               legend='Adjusted Closing Prices')
        b.title = "%s Adjusted Closing Prices" % (stock)
        b.grid.grid_line_alpha = 0.3
        fig_list.append('b')

    if u'Volume' in lst:
        output_file("./templates/stock.html", title=stock)
        c = figure(x_axis_type="datetime", tools=TOOLS)
        c.line(df['Date'], df['Volume'], color='#228B22', legend='Volumes')
        c.title = "%s Volumes" % (stock)
        c.grid.grid_line_alpha = 0.3
        fig_list.append('c')

    if 'a' in fig_list and 'b' in fig_list and 'c' in fig_list:
        p = vplot(hplot(a, b), c)
    elif 'a' in fig_list and 'b' in fig_list:
        p = hplot(a, b)
    elif 'a' in fig_list and 'c' in fig_list:
        p = hplot(a, c)
    elif 'b' in fig_list and 'c' in fig_list:
        p = hplot(b, c)
    elif 'a' in fig_list:
        p = a
    elif 'b' in fig_list:
        p = b
    elif 'c' in fig_list:
        p = c

    save(p)
    return None
Esempio n. 39
0
    def gpu_bars(self, vertical=True, **kwargs):
        gpus = sorted(RessourceMonitor.gpus_comb(subproc_exec=self.normal_exec),
                      key=itemgetter(0))

        devices, free_mems, loads = tuple(zip(*gpus))
        max_free = max(free_mems) * 1.5
        source = ColumnDataSource(self._bar_source(devices,
                                                   ('free', list(free_mems)),
                                                   ('load', list(loads))))

        def waiter():
            change = yield GPUComb
            while not self.terminated:
                self._drop_in(source.data, 'load', change.dev, change.load)
                self._drop_in(source.data, 'free', change.dev, change.free)
                change = yield source

        self.change_consumer.register_waiter(waiter())

        name_range = FactorRange(factors=source.data['name'])

        def makefig(name_range, val_range, val_name, title, ylabel):
            kwargs['x_range'] = name_range
            kwargs['y_range'] = val_range
            kwargs['x_axis_label'] = 'device'
            kwargs['y_axis_label'] = ylabel

            if not vertical:
                self._swapaxes(kwargs)
            return figure(**kwargs, tools=[], title=title)

        p1, p2 = (makefig(name_range, Range1d(0, 100), 'load', 'GPU load', '%'),
                  makefig(name_range, Range1d(0, max_free), 'free',
                          'GPU free memory', 'MiB'))

        if vertical:
            p = vplot(p1, p2)
            p1.quad(left='name_low', right='name_high', top='load',
                    bottom='zeros', source=source)
            p2.quad(left='name_low', right='name_high', top='free',
                    bottom='zeros', source=source)
        else:
            p = hplot(p1, p2)
            p1.quad(left='zeros', right='load', top='name_high',
                    bottom='name_low', source=source)
            p2.quad(left='zeros', right='free', top='name_high',
                    bottom='name_low', source=source)
        p1.add_tools(HoverTool(tooltips=[('load', "@load")]))
        p2.add_tools(HoverTool(tooltips=[('free', "@free")]))
        return p
Esempio n. 40
0
def main():
    # Parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument('--counts', '-c', required=True)
    parser.add_argument('--prefix', '-p')
    parser.add_argument('--title', '-t')
    parser.add_argument('--bins', '-b', type=int)
    parser.add_argument('--y-label', '-y')
    parser.add_argument('--x-label', '-x')
    args = parser.parse_args()
    if args.title:
        title = args.title
    else:
        title = 'Generic Histogram'
    if args.prefix:
        output_filename = args.prefix + '.html'
    else:
        output_filename = 'histogram.html'
    if args.bins:
        bins = args.bins
    else:
        bins = 10 # Bokeh default
    y_label = ""
    if args.y_label:
        y_label = args.y_label
    x_label = ""
    if args.x_label:
        x_label = args.x_label

    # Bokeh magic setup
    output_file(output_filename)
    fig = figure(title=title, tools="pan,wheel_zoom,save",
           background_fill="#E8DDCB")
    fig.left[0].formatter.use_scientific = False
    fig.xaxis.axis_label = x_label
    fig.yaxis.axis_label = y_label

    # Read input file and save counts
    counts = []
    with open(args.counts, 'r') as countfile:
        for line in countfile:
            counts.append(int(line.strip()))

    # Convert to numpy array, then to histogram, then show
    np_counts = np.array(counts)
    hist, edges = np.histogram(counts, bins=bins, density=False)
    fig.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
         fill_color="#036564", line_color="#033649",\
    )
    show(vplot(fig))
Esempio n. 41
0
def make_plots():
    data = pd.read_csv("static/running_data.csv", index_col=False)

    time = [to_dt(x) for x in data.Time]

    dt = max(time)
    last_time = datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute)
    x_name = "date (last updated: " + str(last_time) +")"

    acc = data.Accuracy
    auc = data["ROC-AUC"]
    tp = data["True pos."]
    tn = data["True neg."]
    fp = data["False pos."]
    fn = data["False neg."]

    # Accuracy and AUC
    plot1 = figure(title='Model performance metrics',
                  x_axis_label=x_name,
                  x_axis_type='datetime',
                  y_axis_label='Score')
    plot1.line(time, acc, color = 'black', legend='accuracy', line_width=3)
    plot1.line(time, auc, color='blue', legend='ROC AUC', line_width=3)
    plot1.line(time, tp, color='green', legend='True positive')
    plot1.line(time, tn, color='green', legend='True negative',line_dash=[4, 4])
    plot1.line(time, fp, color='red', legend='False positive')
    plot1.line(time, fn, color='red', legend='False negative',line_dash=[4, 4])
    plot1.legend.location = "bottom_left"
    plot1.y_range = Range1d(0,1)

    plot2 = figure(title='Model performance metrics',
                   x_axis_label=x_name,
                   x_axis_type='datetime',
                   y_axis_label='Score')
    plot2.line(time, tp/(tp + fn), color='black',
               legend='Sensitivity = true positive / actual positive',
               line_width = 3)
    plot2.line(time, tn/(fp + tn), color='blue',
               legend='Specificity = true negative / actual negative',
               line_width = 3)
    plot2.legend.location = "bottom_left"
    plot2.y_range = Range1d(0, 1)

    # Combine the plots
    p = vplot(plot1, plot2)

    output_file("templates/runningscore.html")

    save(p)
Esempio n. 42
0
def main(options, args):

    logger = log.get_logger("ginga", options=options)

    TOOLS = "pan,wheel_zoom,box_select,tap"

    # create a new plot with default tools, using figure
    fig = figure(x_range=[0, 600],
                 y_range=[0, 600],
                 plot_width=600,
                 plot_height=600,
                 tools=TOOLS)

    viewer = ib.CanvasView(logger)
    viewer.set_figure(fig)

    ## box_select_tool = fig.select(dict(type=BoxSelectTool))
    ## box_select_tool.select_every_mousemove = True
    #tap_tool = fig.select_one(TapTool).renderers = [cr]

    # open a session to keep our local document in sync with server
    session = push_session(curdoc())

    #curdoc().add_periodic_callback(update, 50)

    def load_file(path):
        image = AstroImage(logger)
        image.load_file(path)
        viewer.set_image(image)

    def load_file_cb(attr_name, old_val, new_val):
        #print(attr_name, old_val, new_val)
        load_file(new_val)

    # add a entry widget and configure with the call back
    dstdir = options.indir
    path_w = TextInput(value=dstdir, title="File:")
    path_w.on_change('value', load_file_cb)

    curdoc().add_root(vplot(fig, path_w))

    if len(args) > 0:
        load_file(args[0])

    # open the document in a browser
    session.show()

    # run forever
    session.loop_until_closed()
Esempio n. 43
0
def do_step(document):
    document.clear()

    sl, c = next(examples)

    p = plot_slice(sl)

    b_A = Button(label="Accept")
    b_R = Button(label="Reject")

    b_A.on_click(functools.partial(callback, sl, c, 'accept'))
    b_R.on_click(functools.partial(callback, sl, c, 'reject'))

    plot = vplot(p, (hplot(b_A, b_R)))

    document.add_root(plot)
Esempio n. 44
0
def do_step(document):
    document.clear()

    sl, c = next(examples)

    p = plot_slice(sl)

    b_A = Button(label="Accept")
    b_R = Button(label="Reject")

    b_A.on_click(functools.partial(callback, sl, c, 'accept'))
    b_R.on_click(functools.partial(callback, sl, c, 'reject'))

    plot = vplot(p, (hplot(b_A, b_R)))

    document.add_root(plot)
Esempio n. 45
0
    def initPlotArea(self, style=None):
        self.plotArea = figure(plot_width=100,
                               plot_height=100,
                               background_fill="#c1c1c1",
                               border_fill="#c1c1c1",
                               min_border=0)

        self.plotArea.xaxis.visible = False
        self.plotArea.yaxis.visible = False
        self.plotArea.toolbar_location = None
        self.scatter = self.plotArea.scatter([0], [0],
                                             marker=style.lower(),
                                             size=88)

        self.html = vplot(self.plotArea)
        self.drawSymbol(self.html)
        return self.html
Esempio n. 46
0
def build_plot():
    global PLOTS
    global NEW_PTS
    args = request.args
    color = colors[getitem(args, 'color', 'Black')]
    _from = int(getitem(args, '_from', 0))
    to = int(getitem(args, 'to', 10))
    x = list(range(_from, to + 1))

    model1 = get_forecast_data(model1_file)
    model2 = get_forecast_data(model2_file)

    for city in ['denver', 'ny', 'chicago', 'seattle', 'sf']:
        for cartype in ['uberX', 'uberXL', 'uberBLACK', 'uberSUV']:
            p, ds = create_plots(model1, model2, city, cartype)
            PLOTS.append(p)
            NEW_PTS.append((city, cartype, ds))
    ps = vplot(PLOTS[0])
Esempio n. 47
0
    def symbol_val(self, color=None, size=None, outLine=None, visible=None):
        symbol = self.scatter.glyph
        if color:
            symbol.fill_color = color
        if size is not None:
            symbol.size = size
        # if outLine:
        # 	self.symbol_outLine(**outLine)
        if visible is not None:
            symbol.visible = visible

        # self.val.update({'color'   : symbol.fill_color})
        # self.val.update({'size'    : symbol.size})
        # # self.val.update({'outLine' : self.outLine})
        # self.val.update({'visible' : symbol.visible})
        # return self.val
        self.html = vplot(self.plotArea)
        self.drawSymbol(self.html)
        return self.html
def bokeh2(X):
    Y = de_mean_matrix(X)

    TOOLS = "resize,crosshair,pan,wheel_zoom,box_zoom,reset,previewsave,box_select"

    hover = HoverTool(tooltips=[
        ("index", "$index"),
        ("(x,y)", "($x, $y)"),
        ("desc", "@desc"),
    ])

    bplt.output_file("data.html", title="Rescaling")

    s1 = bplt.figure(width=500,
                     plot_height=250,
                     title="Data",
                     tools=[hover, TOOLS])
    s1.scatter(X[:, 0].A1,
               X[:, 1].A1,
               marker="circle",
               line_color="#6666ee",
               fill_color="#ee6666",
               fill_alpha=0.5,
               size=12)

    s2 = bplt.figure(width=500,
                     plot_height=250,
                     title="De-meaned",
                     tools=TOOLS)
    s2.scatter(Y[:, 0].A1,
               Y[:, 1].A1,
               marker="circle",
               line_color="#6666ee",
               fill_color="#ee6666",
               fill_alpha=0.5,
               size=12)

    # put all the plots in a VBox
    p = bplt.vplot(s1, s2)

    # show the results
    bplt.show(p)
Esempio n. 49
0
def plot_multi_test():
    nelem = 100

    samples = np.squeeze(
        np.dstack([np.random.normal(size=nelem),
                   np.random.normal(size=nelem)]))

    bwlist = [approx_bandwidth(samples[:, k]) for k in range(samples.shape[1])]
    bandwidths = np.array(bwlist)

    support = build_support_nd(samples, bandwidths)

    pdf = np.zeros(support.shape[0], dtype=np.float64)

    print('bandwidths', bandwidths)
    print('support', support.shape)
    print('samples', samples.shape)

    multi_kde_seq(support, samples, bandwidths, pdf)

    kde = sm.nonparametric.KDEMultivariate(samples, var_type='cc', bw=bwlist)
    expect_pdf = kde.pdf(support)

    # Plotting

    output_file("kde_multi.html")

    cm = RGBColorMapper(0, 1, palettes.Spectral11)

    p1 = figure(title="KDE")
    p1.square(support[:, 0],
              support[:, 1],
              size=5,
              color=cm.color(pdf / np.ptp(pdf)))

    p2 = figure(title="KDE-SM")
    p2.square(support[:, 0],
              support[:, 1],
              size=5,
              color=cm.color(expect_pdf / np.ptp(expect_pdf)))

    show(vplot(p1, p2))
Esempio n. 50
0
def worker_table_plot(width=600, height="auto", **kwargs):
    """ Column data source and plot for host table """
    names = [
        'workers', 'cpu', 'memory-percent', 'memory', 'cores', 'processes',
        'processing', 'latency', 'last-seen', 'disk-read', 'disk-write',
        'network-send', 'network-recv'
    ]
    source = ColumnDataSource({k: [] for k in names})

    columns = {name: TableColumn(field=name, title=name) for name in names}

    slow_names = [
        'workers', 'cores', 'processes', 'memory', 'latency', 'last-seen'
    ]
    slow = DataTable(source=source,
                     columns=[columns[n] for n in slow_names],
                     width=width,
                     height=height,
                     **kwargs)
    slow.columns[3].formatter = NumberFormatter(format='0.0 b')
    slow.columns[4].formatter = NumberFormatter(format='0.00000')
    slow.columns[5].formatter = NumberFormatter(format='0.000')

    fast_names = [
        'workers', 'cpu', 'memory-percent', 'processing', 'disk-read',
        'disk-write', 'network-send', 'network-recv'
    ]
    fast = DataTable(source=source,
                     columns=[columns[n] for n in fast_names],
                     width=width,
                     height=height,
                     **kwargs)
    fast.columns[1].formatter = NumberFormatter(format='0.0 %')
    fast.columns[2].formatter = NumberFormatter(format='0.0 %')
    fast.columns[4].formatter = NumberFormatter(format='0 b')
    fast.columns[5].formatter = NumberFormatter(format='0 b')
    fast.columns[6].formatter = NumberFormatter(format='0 b')
    fast.columns[7].formatter = NumberFormatter(format='0 b')

    table = vplot(slow, fast)
    return source, table
Esempio n. 51
0
def worker_table_plot(width=600, height=100, **kwargs):
    """ Column data source and plot for host table """
    names = ['workers', 'cpu', 'memory-percent', 'memory', 'cores', 'processes',
             'processing', 'latency', 'last-seen', 'disk-read', 'disk-write',
             'network-send', 'network-recv']
    source = ColumnDataSource({k: [] for k in names})

    columns = {name: TableColumn(field=name, title=name) for name in names}

    slow_names = ['workers', 'cores', 'processes', 'memory',
                  'latency', 'last-seen']
    slow = DataTable(source=source, columns=[columns[n] for n in slow_names],
                     width=width, height=height, **kwargs)

    fast_names = ['workers', 'cpu', 'memory-percent', 'processing',
            'disk-read', 'disk-write', 'network-send', 'network-recv']
    fast = DataTable(source=source, columns=[columns[n] for n in fast_names],
                     width=width, height=height, **kwargs)

    table = vplot(slow, fast)
    return source, table
def make_interactive(plot):
    plot = add_legend(plot)

    for year in years:
        fertility = fertility_df[year]
        fertility.name = 'fertility'
        life = life_expectancy_df[year]
        life.name = 'life'
        population = population_df_size[year]
        population.name = 'population'
        new_df = pd.concat([fertility, life, population, region_color], axis=1)
        sources['_' + str(year)] = ColumnDataSource(new_df)

    dictionary_of_sources = dict(
        zip([x for x in years], ['_%s' % x for x in years]))
    js_source_array = str(dictionary_of_sources).replace("'", "")

    # Add the slider
    code = """
        var year = slider.get('value'),
            sources = %s,
            new_source_data = sources[year].get('data');
        renderer_source.set('data', new_source_data);
        renderer_source.trigger('change');
        text_source.set('data', {'year': [String(year)]});
        text_source.trigger('change');
    """ % js_source_array

    callback = CustomJS(args=sources, code=code)
    slider = Slider(start=years[0],
                    end=years[-1],
                    value=1,
                    step=1,
                    title="Year",
                    callback=callback)
    callback.args["slider"] = slider
    callback.args["renderer_source"] = renderer_source
    callback.args["text_source"] = text_source

    return vplot(plot, slider)
Esempio n. 53
0
    def setScatterSymbol(self, val="Circle"):
        models = bokeh.models.glyphs

        changeVal = self.scatter.glyph.changed_properties_with_values()
        glyph = {
            "Circle": models.Circle(**changeVal),
            "CircleX": models.CircleX(**changeVal),
            "Cross": models.Cross(**changeVal),
            "Diamond": models.Diamond(**changeVal),
            "DiamondCross": models.DiamondCross(**changeVal),
            "Square": models.Square(**changeVal),
            "SquareX": models.SquareX(**changeVal),
            "InvertedTriangle": models.InvertedTriangle(**changeVal),
            "Triangle": models.Triangle(**changeVal),
            "X": models.X(**changeVal),
            "Asterisk": models.Asterisk(**changeVal)
        }

        self.scatter.set(glyph=glyph[val])
        self.html = vplot(self.plotArea)
        self.drawSymbol(self.html)
        return self.html
Esempio n. 54
0
def plot_uni_test():
    samples = mixture_rvs([.25, .75],
                          size=10000,
                          dist=[stats.norm, stats.norm],
                          kwargs=(dict(loc=-1, scale=.5), dict(loc=1,
                                                               scale=.5)))

    bandwidth = approx_bandwidth(samples)

    print('bandwidth', bandwidth)
    print('size', samples.size)

    support = build_support(samples, bandwidth)
    pdf = np.zeros_like(support)

    uni_kde_seq(support, samples, bandwidth, pdf)

    # Plotting
    output_file("kde.html")

    p1 = figure(title="Hist")
    hist, edges = np.histogram(samples, bins=50, density=True)
    p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:])

    p2 = figure(title="KDE")
    p2.line(support, pdf)
    p2.circle(x=support, y=pdf, size=5)

    p3 = figure(title="KDE-SM")
    kde = sm.nonparametric.KDEUnivariate(samples)
    kde.fit(kernel="gau")

    p3.line(kde.support, kde.density)

    print(samples.size)
    print(len(kde.support), len(kde.density))

    print(kde.density.sum())
    show(vplot(p1, p2, p3))
Esempio n. 55
0
def index():
    # Create layout
    c_map = climate_map()
    ts = timeseries()
    l = legend()
    t = title()

    map_legend = hplot(c_map, l)
    layout = vplot(t, map_legend, ts)

    plot_resources = RESOURCES.render(
        js_raw=INLINE.js_raw,
        css_raw=INLINE.css_raw,
        js_files=INLINE.js_files,
        css_files=INLINE.css_files,
    )
    script, div = components(layout, INLINE)
    html = flask.render_template(
        'embed.html',
        plot_script=script,
        plot_div=div,
        plot_resources=plot_resources,
    )
    return encode_utf8(html)
# Read counts into a list
barcode_counts = []
with open(sys.argv[1], 'r') as counts:
    for line in counts:
        barcode_counts.append(int(line.strip()))

output_file('histogram.html')

p1 = figure(title="Barcode Read Counts",
            tools="save,box_zoom,pan,ywheel_zoom",
            background_fill="#E8DDCB")

barcode_counts = np.array(barcode_counts)
# TODO manually set bins
hist, edges = np.histogram(barcode_counts,
                           density=False,
                           bins=[
                               0, 100, 200, 300, 400, 500, 600, 700, 800, 900,
                               1000, 1500, 2000, 2500, 3000, 3500, 4000, 4500,
                               5000, 7500, 10000
                           ])

p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
             fill_color="#036564", line_color="#033649",\
                     )

p1.xaxis.axis_label = 'Number of Reads'
p1.yaxis.axis_label = 'Barcode Count'

show(vplot(p1))
Esempio n. 57
0
    def gpu_bars(self, vertical=True, **kwargs):
        gpus = sorted(
            RessourceMonitor.gpus_comb(subproc_exec=self.normal_exec),
            key=itemgetter(0))

        devices, free_mems, loads = tuple(zip(*gpus))
        max_free = max(free_mems) * 1.5
        source = ColumnDataSource(
            self._bar_source(devices, ('free', list(free_mems)),
                             ('load', list(loads))))

        def waiter():
            change = yield GPUComb
            while not self.terminated:
                self._drop_in(source.data, 'load', change.dev, change.load)
                self._drop_in(source.data, 'free', change.dev, change.free)
                change = yield source

        self.change_consumer.register_waiter(waiter())

        name_range = FactorRange(factors=source.data['name'])

        def makefig(name_range, val_range, val_name, title, ylabel):
            kwargs['x_range'] = name_range
            kwargs['y_range'] = val_range
            kwargs['x_axis_label'] = 'device'
            kwargs['y_axis_label'] = ylabel

            if not vertical:
                self._swapaxes(kwargs)
            return figure(**kwargs, tools=[], title=title)

        p1, p2 = (makefig(name_range, Range1d(0, 100), 'load', 'GPU load',
                          '%'),
                  makefig(name_range, Range1d(0, max_free), 'free',
                          'GPU free memory', 'MiB'))

        if vertical:
            p = vplot(p1, p2)
            p1.quad(left='name_low',
                    right='name_high',
                    top='load',
                    bottom='zeros',
                    source=source)
            p2.quad(left='name_low',
                    right='name_high',
                    top='free',
                    bottom='zeros',
                    source=source)
        else:
            p = hplot(p1, p2)
            p1.quad(left='zeros',
                    right='load',
                    top='name_high',
                    bottom='name_low',
                    source=source)
            p2.quad(left='zeros',
                    right='free',
                    top='name_high',
                    bottom='name_low',
                    source=source)
        p1.add_tools(HoverTool(tooltips=[('load', "@load")]))
        p2.add_tools(HoverTool(tooltips=[('free', "@free")]))
        return p