Example #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 empty_plot():
    p = figure(
        tools="hover,wheel_zoom,reset",
        width=FIGURE_WIDTH,
        responsive=True,
        tags=["clusterPlot"],
    )

    # Ensure that the lasso only selects with mouseup, not mousemove.
    p.add_tools(LassoSelectTool(select_every_mousemove=False))

    # These turn off the x/y axis ticks
    p.axis.visible = None

    # These turn the major grid off
    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = None

    # Plot non-selected circles with a particular style using CIRCLE_SIZE and
    # 'color' list
    but_relevant = Button(label="Relevant", type="success")
    but_irrelevant = Button(label="Irrelevant", type="success")
    but_neutral = Button(label="Neutral", type="success")
    custom_tag_input = TextInput(value="Add custom tag...")
    custom_tag_select = Select(value="Custom tags", options=["Custom tags"])
    but_backward_crawl = Button(label="Backlinks", type="success")
    but_forward_crawl = Button(label="Forwardlinks", type="success")
    
    tags = hplot(custom_tag_input, custom_tag_select, but_relevant, but_irrelevant, but_neutral)
    tags_crawl = hplot(but_backward_crawl, but_forward_crawl)
    layout = vform(p, tags, tags_crawl)

    # Combine script and div into a single string.
    plot_code = components(layout)
    return plot_code[0] + plot_code[1]
Example #3
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
Example #4
0
    def create_occurance_figure(self, sentence, open_plots=False):
        """
        Gets dictionaries of occurances on a sentence
        and the normal occurances at the english language
        """
        self.stm = self.se.statistical_monograms(sentence, sort_r=True)
        self.sa = self.se.occurances

        """
        Create key item pair lists for each dictionary
        """
        keys = [m[0] for m in self.stm ]
        items = [m[1] for m in self.stm ]
        keys_a = [m[0] for m in self.sa ]
        items_a = [m[1] for m in self.sa ]

        """
        Creates a figure of each dictionary
        """
        p = figure(x_range=keys, title="Encrypted Sentence letter occurance")
        p.square(keys, items)
        s = figure(x_range=keys_a, title="Normal letter occurance")
        s.square(keys_a, items_a)
        """
        Creates a plot and opens it in a webbrowser if desired
        """
        v = hplot(p, s)
        if open_plots:
            show(v)
Example #5
0
    def console(self, stdout=True, stderr=True, **kwargs):
        console_kwargs = dict((key, kwargs[key])
                              for key in ['n', 'max_line_len', 'input_bottom']
                              if key in kwargs)

        consoles = list()

        def waiter(sentinel, console: BokehConsole):
            change = yield sentinel
            if hasattr(sentinel, 'bytes'):
                while not self.terminated:
                    console.output_text(change.bytes.decode())
                    change = yield console.source
            else:
                while not self.terminated:
                    console.output_text(change.text)
                    change = yield console.source

        if stdout:
            c = BokehConsole(**console_kwargs)
            self.change_consumer.register_waiter(waiter(BytesStdOut, c))
            self.change_consumer.register_waiter(waiter(TextStdOut, c))
            consoles.append(c)

        if stderr:
            c = BokehConsole(**console_kwargs)
            self.change_consumer.register_waiter(waiter(BytesStdErr, c))
            self.change_consumer.register_waiter(waiter(TextStdErr, c))
            consoles.append(c)

        if len(consoles) == 1:
            return consoles[0].p
        return hplot(*(c.p for c in consoles))
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))
Example #7
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)))
Example #8
0
    def calculate_average_accuracy(self, confusion_matrix):
        if confusion_matrix is None:
            return None

        scores = []
        n = np.shape(confusion_matrix)[0]
        mean_acc = 0
        for index, r in enumerate(confusion_matrix):
            ss = sum(r)
            if ss != 0:
                scores.append(float(r[index]) / ss)

        scores = np.hstack((scores, np.mean(scores)))
        class_labels = self.class_labels[:]
        class_labels.append('average')
        data = {"accuracy": scores}
        s = Bar(data,
                cat=class_labels,
                title="Per Class Accuracy",
                xlabel='categories',
                ylabel='accuracy',
                width=500,
                height=500,
                tools="pan,resize,box_zoom,hover,save,reset",
                stacked=True,
                palette=["#ec5d5e"])

        hover = s.select(dict(type=HoverTool))
        hover.tooltips = OrderedDict([
            ('accuracy', '@accuracy'),
        ])

        p = hplot(s)
        script, div = components(p)
        return (script, div)
Example #9
0
    def calculate_average_accuracy(self, confusion_matrix):
        if confusion_matrix is None:
            return None

        scores = []
        n = np.shape(confusion_matrix)[0]
        mean_acc = 0
        for index, r in enumerate(confusion_matrix):
            ss = sum(r)
            if ss != 0:
                scores.append(float(r[index]) / ss)
            

        scores = np.hstack((scores,np.mean(scores)))
        class_labels = self.class_labels[:]
        class_labels.append('average')
        data = {"accuracy": scores}
        s = Bar(data, cat=class_labels, title="Per Class Accuracy",
        xlabel='categories', ylabel='accuracy', width=500, height=500,
        tools="pan,resize,box_zoom,hover,save,reset", stacked=True, palette=["#ec5d5e"])  
        
        hover = s.select(dict(type=HoverTool))
        hover.tooltips = OrderedDict([
                         ('accuracy', '@accuracy'),
                          ])

        p = hplot(s)
        script, div = components(p)
        return (script, div)
Example #10
0
    def console(self, stdout=True, stderr=True, **kwargs):
        console_kwargs = dict(
            (key, kwargs[key]) for key in ['n', 'max_line_len', 'input_bottom']
            if key in kwargs)

        consoles = list()

        def waiter(sentinel, console: BokehConsole):
            change = yield sentinel
            if hasattr(sentinel, 'bytes'):
                while not self.terminated:
                    console.output_text(change.bytes.decode())
                    change = yield console.source
            else:
                while not self.terminated:
                    console.output_text(change.text)
                    change = yield console.source

        if stdout:
            c = BokehConsole(**console_kwargs)
            self.change_consumer.register_waiter(waiter(BytesStdOut, c))
            self.change_consumer.register_waiter(waiter(TextStdOut, c))
            consoles.append(c)

        if stderr:
            c = BokehConsole(**console_kwargs)
            self.change_consumer.register_waiter(waiter(BytesStdErr, c))
            self.change_consumer.register_waiter(waiter(TextStdErr, c))
            consoles.append(c)

        if len(consoles) == 1:
            return consoles[0].p
        return hplot(*(c.p for c in consoles))
	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)
Example #12
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_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 main(argv):
	fig = plt.figure()
	ax = fig.add_subplot(121)
	N = 200

	x = np.linspace(0, 10, N)
	y = np.linspace(0, 10, N)
	xx, yy = np.meshgrid(x, y)
	d = np.sin(xx)*np.cos(2*yy)+.1*yy
	d = d + .015*np.random.rand(*xx.shape)

	cn = plt.contourf(x,y,d,9, extend = "both")

	ax2 = fig.add_subplot(122)
	ax2.xlim = [0,10]
	ax2.ylim = [0,10]

	html_size_without_plots = 1638397 # bytes
	html_size_with_p0_only = 1901692 # bytes
	html_size_with_p1_only = 2463969 # bytes 

	output_file('filled_contours.html', title='filled contours')
	p0 = figure(x_range=[0, 10], y_range=[0, 10])
	filled_contours(p0, cn,.02)
	p0.title = str((html_size_with_p0_only-html_size_without_plots)/1000.) + ' Kb'

	p1 = figure(x_range=[0, 10], y_range=[0, 10])
	p1.image(image = [d], x=[0], y=[0], dw=10, dh=10, palette="Spectral11")
	p1.title = str((html_size_with_p1_only-html_size_without_plots)/1000.) + ' Kb'
	show(hplot(p0, p1))
Example #15
0
 def __init__(self, size):
     self.size = size
     
     self.time = RingBuffer(size)
     self.i_corr = RingBuffer(size)
     self.q_corr = RingBuffer(size)
     self.phase_error = RingBuffer(size)
     self.delay_error = RingBuffer(size)
     
     plot = figure(title='i corr', plot_width=250, plot_height=250, tools="pan,wheel_zoom,box_zoom,reset,save")
     plot.line(self.time.get(), self.i_corr.get(), size=12, alpha=0.7, name='i_corr')
     self.i_corr_plot = plot
     
     plot = figure(title='q corr', plot_width=250, plot_height=250, tools="pan,wheel_zoom,box_zoom,reset,save")
     plot.line(self.time.get(), self.q_corr.get(), size=12, alpha=0.7, name='q_corr')
     self.q_corr_plot = plot
     
     plot = figure(title='phase error', plot_width=250, plot_height=250, tools="pan,wheel_zoom,box_zoom,reset,save")
     plot.line(self.time.get(), self.phase_error.get(), size=12, alpha=0.7, name='phase_error')
     self.phase_error_plot = plot
     
     plot = figure(title='delay error', plot_width=250, plot_height=250, tools="pan,wheel_zoom,box_zoom,reset,save")
     plot.line(self.time.get(), self.delay_error.get(), size=12, alpha=0.7, name='delay_error')
     self.delay_error_plot = plot
     
     children = [self.i_corr_plot, self.q_corr_plot, self.phase_error_plot, self.delay_error_plot]
     self.plot = hplot(*children, name="tracking outputs")
Example #16
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)
Example #17
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
Example #18
0
    def plot_scores2(self):

        if self.scores is None:
            return None

        scores = np.vstack(self.scores)
        data = OrderedDict()
        for i in xrange(len(self.class_labels)):
            data[self.class_labels[i]] = scores[:2, i]
        s1 = Bar(data,
                 cat=['precision', 'recall'],
                 title="Per Class Scores",
                 width=500,
                 height=500,
                 legend=True,
                 tools="pan,resize,box_zoom,hover,save,reset")

        data = OrderedDict()
        for i in xrange(len(self.class_labels)):
            data[self.class_labels[i]] = scores[3:4, i]
        s2 = Bar(data,
                 cat=['support'],
                 title="Support",
                 width=500,
                 height=500,
                 legend=True,
                 tools="pan,resize,box_zoom,hover,save,reset")

        p = hplot(s1, s2)

        script, div = components(p)
        return (script, div)
def main(argv):
    fig = plt.figure()
    ax = fig.add_subplot(121)
    N = 200

    x = np.linspace(0, 10, N)
    y = np.linspace(0, 10, N)
    xx, yy = np.meshgrid(x, y)
    d = np.sin(xx) * np.cos(2 * yy) + 0.1 * yy
    d = d + 0.015 * np.random.rand(*xx.shape)

    cn = plt.contourf(x, y, d, 9, extend="both")

    ax2 = fig.add_subplot(122)
    ax2.xlim = [0, 10]
    ax2.ylim = [0, 10]

    html_size_without_plots = 1638397  # bytes
    html_size_with_p0_only = 1901692  # bytes
    html_size_with_p1_only = 2463969  # bytes

    output_file("filled_contours.html", title="filled contours")
    p0 = figure(x_range=[0, 10], y_range=[0, 10])
    filled_contours(p0, cn, 0.02)
    p0.title = str((html_size_with_p0_only - html_size_without_plots) / 1000.0) + " Kb"

    p1 = figure(x_range=[0, 10], y_range=[0, 10])
    p1.image(image=[d], x=[0], y=[0], dw=10, dh=10, palette="Spectral11")
    p1.title = str((html_size_with_p1_only - html_size_without_plots) / 1000.0) + " Kb"
    show(hplot(p0, p1))
def empty_plot():
    p = figure(
        tools="hover,wheel_zoom,reset",
        width=FIGURE_WIDTH,
        height=FIGURE_HEIGHT,
        responsive=True,
        tags=["clusterPlot"],
        min_border_bottom=MIN_BORDER_BOTTOM,
        min_border_top=MIN_BORDER_TOP,
        min_border_left=MIN_BORDER_LEFT,
        min_border_right=MIN_BORDER_RIGHT,
    )

    # Ensure that the lasso only selects with mouseup, not mousemove.
    p.add_tools(LassoSelectTool(select_every_mousemove=False))

    # These turn off the x/y axis ticks
    p.axis.visible = None

    # These turn the major grid off
    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = None

    # Plot non-selected circles with a particular style using CIRCLE_SIZE and
    # 'color' list
    but_relevant = Button(label="Relevant", type="success")
    but_irrelevant = Button(label="Irrelevant", type="success")
    but_neutral = Button(label="Neutral", type="success")
    custom_tag_input = TextInput(value="Add custom tag...")
    custom_tag_select = Select(value="Custom tags", options=["Custom tags"])
    but_backward_crawl = Button(label="Backlinks", type="success")
    but_forward_crawl = Button(label="Forwardlinks", type="success")

    tags = hplot(but_relevant,
                 but_irrelevant,
                 but_neutral,
                 custom_tag_input,
                 custom_tag_select,
                 height=40)
    tags_crawl = hplot(but_backward_crawl, but_forward_crawl)
    layout = vform(p, tags, tags_crawl)

    # Combine script and div into a single string.
    plot_code = components(layout)
    return plot_code[0] + plot_code[1]
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)
Example #23
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,
    )]
Example #24
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,
    )]
Example #25
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
Example #26
0
 def plot_scores(self, all_scores):
     
     if all_scores is None:
         return None
     
     scores = all_scores[0][:]
     scores = np.hstack((scores,np.mean(scores)))
     class_labels = self.class_labels[:]
     class_labels.append('average')
     data = {"precision": scores}
     s1 = Bar(data, cat=class_labels, title="Per Class Precision",
     xlabel='categories', ylabel='precision', width=500, height=500,
     tools="pan,resize,box_zoom,hover,save,reset", stacked=True, palette=["#b2df8a"])    
     
     hover = s1.select(dict(type=HoverTool))
     hover.tooltips = OrderedDict([
                      ('precision', '@precision'),
                       ])
     
     scores = all_scores[1][:]
     scores = np.hstack((scores,np.mean(scores)))
     class_labels = self.class_labels[:]
     class_labels.append('average')
     data = {"recall": scores}
     s2 = Bar(data, cat=class_labels, title="Per Class Recall",
     xlabel='categories', ylabel='recall', width=500, height=500,
     tools="pan,resize,box_zoom,hover,save,reset", stacked=True, palette=["#a6cee3"])  
     
     hover = s2.select(dict(type=HoverTool))
     hover.tooltips = OrderedDict([
                      ('recall', '@recall'),
                       ])
     
     data = {"support": all_scores[3]}
     s3 = Bar(data, cat=self.class_labels, title="Per Class Support",
     xlabel='categories', ylabel='support', width=500, height=500,
     tools="pan,resize,box_zoom,hover,save,reset", stacked=True, palette=["#6a3d9a"])    
     
     hover = s3.select(dict(type=HoverTool))
     hover.tooltips = OrderedDict([
                      ('support', '@support'),
                       ])
                       
     p = hplot(s1, s2, s3)
     
  
     
     script, div = components(p)
     return (script, div)
Example #27
0
def my_link(s1):
    ex = db.get_data(fname=s1)[0]
    # patterns = []
    # for foot in range(2):
    #     for st in ex.steps_annotation[foot]:
    #           if st[1]-st[0] < 30:
    #               continue
    #     patterns += [Pattern(dict(coord='RY', l_pat=st[1]-st[0],
    #                                       foot='right' if foot else 'left'),
    #                                  ex.data_sensor[6*foot+4, st[0]:st[1]])]
    #     patterns += [Pattern(dict(coord='AZ', l_pat=st[1]-st[0],
    #                                       foot='right' if foot else 'left'),
    #                                  ex.data_sensor[6*foot+2, st[0]:st[1]])]
    #     patterns += [Pattern(dict(coord='AV', l_pat=st[1]-st[0],
    #                                       foot='right' if foot else 'left'),
    #                                  ex.data_earth[6*foot+2, st[0]:st[1]])]
    # stepDet = StepDetection(patterns=patterns, lmbd=.8, mu=.1)
    # steps, steps_label = stepDet.compute_steps(ex)
    # print('steps: ',steps)


    seg = ex.seg_annotation
    print('segm: ',seg)
    print(ex.DAZ[0][seg[1]:seg[2]].T)

    T = len(ex.DAZ[0][seg[0]:seg[1]])
    t = np.arange(T)/100
    plot = figure(width=350, plot_height=250, title="Aller")
    plot.line(t,ex.DAZ[0][seg[0]:seg[1]])

    T = len(ex.DAZ[0][seg[1]:seg[2]])
    t = np.arange(T)/100
    plot1 = figure(width=350, plot_height=250, title="u-Turn")
    plot1.line(t,ex.DAZ[0][seg[1]:seg[2]])

    T = len(ex.DAZ[0][seg[2]:seg[3]])
    t = np.arange(T)/100
    plot2 = figure(width=350, plot_height=250, title="Return")
    plot2.line(t,ex.DAZ[0][seg[2]:seg[3]])

    p = hplot(plot, plot1, plot2)

    tab1 = Panel(child=p, title="Segmentation")

    tabs = Tabs(tabs=[tab1])
    text_input = TextInput(value=ex.fname, title="Enregistrement: ")
    layout = vform(text_input, tabs)
    html = file_html(layout, CDN, "home2")
    return html
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)
Example #29
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)
Example #30
0
def plot_outputs(store, library='bokeh'):
    keys = store.outputs.keys()
    n = len(keys)
    fig = None
    rows = cols = int(ceil(sqrt(n)))
    if library is 'matplotlib':
        fig = fig if fig else pyplot.figure()
        for i, key in enumerate(keys, 1):
            ax = fig.add_subplot(rows, cols, i)
            ax.plot(store.buffers[key])
            ax.set_title(key)
        return fig
    elif library is 'bokeh':
        plots = []
        for key in store.outputs.keys():
            plot = figure(title=key, plot_width=250, plot_height=250, tools="pan,wheel_zoom,box_zoom,reset,save")
            plot.line(arange(store.outputs[key]['size']), store.buffers[key], size=12, alpha=0.7)
            plots.append(plot)
        plot = hplot(*plots, name="tracking outputs")
        return plot
    return None
Example #31
0
 def plot_scores2(self):
     
     if self.scores is None:
         return None
     
     scores = np.vstack(self.scores)
     data = OrderedDict()
     for i in xrange(len(self.class_labels)):
         data[self.class_labels[i]] = scores[:2, i]
     s1 = Bar(data, cat=['precision', 'recall'], title="Per Class Scores",
     width=500, height=500, legend=True, tools="pan,resize,box_zoom,hover,save,reset")    
     
     data = OrderedDict()
     for i in xrange(len(self.class_labels)):
         data[self.class_labels[i]] = scores[3:4, i]
     s2 = Bar(data, cat=['support'], title="Support",
     width=500, height=500, legend=True, tools="pan,resize,box_zoom,hover,save,reset")   
     
     p = hplot(s1,s2)
     
     script, div = components(p)
     return (script, div)    
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)
Example #33
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)
vhist, vedges = np.histogram(y, bins=20)
vzeros = np.zeros(len(vedges)-1)
vmax = max(vhist)*1.1

# need to adjust for toolbar height, unfortunately
th = 42

pv = figure(toolbar_location=None, plot_width=200, plot_height=p.plot_height+th-10, x_range=(-vmax, vmax),
            y_range=p.y_range, title=None, min_border=10, min_border_top=th)
pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vhist, color="white", line_color="#3A5785")
pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vzeros, color="#3A5785", alpha=0.5, line_color=None, name="vhist")
pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vzeros, color="#3A5785", alpha=0.1, line_color=None, name="vhist2")
pv.ygrid.grid_line_color = None

session = push_session(curdoc())
layout = vplot(hplot(p, pv), hplot(ph, Paragraph()))
session.show(layout)

ph_source = ph.select(dict(name="hhist"))[0].data_source
ph_source2 = ph.select(dict(name="hhist2"))[0].data_source

pv_source = pv.select(dict(name="vhist"))[0].data_source
pv_source2 = pv.select(dict(name="vhist2"))[0].data_source

# set up callbacks
def on_selection_change(attr, old, new):
    inds = np.array(new['1d']['indices'])
    if len(inds) == 0 or len(inds) == len(x):
        hhist = hzeros
        vhist = vzeros
        hhist2 = hzeros
Example #35
0
            plot_width=plt_width,
            plot_height=plt_height)
p2.line(time_x,
        HF_data,
        color="#0000dd",
        line_width=line_width,
        line_dash='dashed')

p2.title_text_font_size = title_size
p2.xaxis.axis_label_text_font_size = axis_label_size
p2.yaxis.axis_label_text_font_size = axis_label_size
p2.xaxis.major_label_text_font_size = tick_label_size
p2.yaxis.major_label_text_font_size = tick_label_size
p2.yaxis.axis_label_standoff = 10

p = hplot(p1, p2)

session = push_session(curdoc())

renderer = p1.select(dict(type=GlyphRenderer))
ds1 = renderer[0].data_source
renderer = p2.select(dict(type=GlyphRenderer))
ds2 = renderer[0].data_source


def update():
    new_data = pd.read_csv(args.data_file, index_col=0)
    time_x = new_data.iloc[-60:, 1]
    T_data = new_data.iloc[-60:, 4] + 6
    HF_data = new_data.iloc[-60:, 5]
    # new_data = pd.read_csv('../Data/UL_Exp_5_031116_revised.csv')
Example #36
0
 			}, 0);

  			var avg = sum / data.length;
  			return avg;
		}
    """)

p3.line(m_ids, 1.4, line_width=1, legend='Accepted: ' + str(len(m_ids))) #daily accepted
p3.line(m_ids, 1.2, line_width=1, legend='Rejected: ' + str(meco_rejected)) #daily rejected
p3.line(m_ids, 1.2, line_width=2, line_color='green')
p3.line(m_ids, 1.4, line_width=2, line_color='green')
p3.background_fill = 'beige'
p3.xaxis.axis_label = 'Grid Id'
p3.yaxis.axis_label = 'Weights(g)'

tab1 = Panel(child=hplot(p1, p3), title="Weight Distributions") #first tab of the dashboard

#Meco GridThicknesses
p4a = figure(plot_width=700, plot_height=400, title="Meco Thickness Comparison")
center_measurements = [2,5,7,8,10,12,13,14,16]
l_measurements = [1,4,9,15]
r_measurements = [3,6,11,17]
#center thickness
p4a.line(center_measurements, c_thickness_stats['avg'], line_width=2, legend='Center')
p4a.circle(center_measurements, c_thickness_stats['avg'], fill_color='white', size=8)
#left thickness
p4a.line(l_measurements, l_thickness_stats['avg'], line_width=2, legend='Left', color='orange')
p4a.circle(l_measurements, l_thickness_stats['avg'], fill_color='white', size=8)
#right thickness
p4a.line(r_measurements, r_thickness_stats['avg'], line_width=2, legend='Right', color='purple')
p4a.circle(r_measurements, r_thickness_stats['avg'], fill_color='white', size=8)
Example #37
0
    for (i = 0; i < x.length; i++) {
        y[i] = B + A*Math.sin(k*x[i]+phi);
    }
    source.trigger('change');
""")

amp_slider = Slider(start=0.1, end=10, value=1, step=.1,
                    title="Amplitude", callback=callback)
callback.args["amp"] = amp_slider

freq_slider = Slider(start=0.1, end=10, value=1, step=.1,
                     title="Frequency", callback=callback)
callback.args["freq"] = freq_slider

phase_slider = Slider(start=0, end=6.4, value=0, step=.1,
                      title="Phase", callback=callback)
callback.args["phase"] = phase_slider

offset_slider = Slider(start=-5, end=5, value=0, step=.1,
                       title="Offset", callback=callback)
callback.args["offset"] = offset_slider

layout = hplot(
    plot,
    vform(amp_slider, freq_slider, phase_slider, offset_slider),
)

output_file("slider.html", title="slider.py example")

show(layout)
Example #38
0
        execs['localhost'] = async_subprocess, Popen

    _hplots = list()
    monitors = list()
    change_streams = list()
    for ex in execs.values():
        changes = ChangeStream()
        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)
    bokeh_port = args.bp
    mon_port = args.mp
    p_bokeh = start_bokeh(mon_port, bokeh_port, plot_gen, changes)

    scr = autoload_server(plots, session_id=plot_gen.session.id)
    print(scr)
    scr = re.sub('http://localhost:{0}'.format(bokeh_port), '', scr)
    scr = TEMPLATE.format(script=scr).encode()

    loop = asyncio.get_event_loop()
    start_tornado(loop, bokeh_port, mon_port, scr)
    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)))
Example #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
            tools="lasso_select",
            title="Select Here")
p1.circle('x', 'y', source=s1, alpha=0.6)

s2 = ColumnDataSource(data=dict(x=[], y=[]))
p2 = figure(plot_width=400,
            plot_height=400,
            x_range=(0, 1),
            y_range=(0, 1),
            tools="",
            title="Watch Here")
p2.circle('x', 'y', source=s2, alpha=0.6)

s1.callback = CustomJS(args=dict(s2=s2),
                       code="""
        var inds = cb_obj.get('selected')['1d'].indices;
        var d1 = cb_obj.get('data');
        var d2 = s2.get('data');
        d2['x'] = []
        d2['y'] = []
        for (i = 0; i < inds.length; i++) {
            d2['x'].push(d1['x'][inds[i]])
            d2['y'].push(d1['y'][inds[i]])
        }
        s2.trigger('change');
    """)

layout = hplot(p1, p2)

show(layout)
Example #41
0
def ngramgraph():
    pwidth = 550
    pheight = 400
    # Grab the inputs arguments from the URL
    # This is automated by the button
    args = request.args

    # Get all the form arguments in the url with defaults
    #default to obama
    query = getitem(args, 'input', 'obama')

    #splittign the query
    splitstr = query.split(",")

    #Fetching data from the query
    XX = []
    YY = []
    YY2 = []
    lgnd = []
    cnt = 0
    source = [] 
    for strs in splitstr:
        ngram = strs.rstrip().lstrip().lower()
        #print "ngram = ", ngram
        subreddits = get_subreddit_data(ngram)
        #print "subreddits", subreddits
        
        if len(subreddits) > 0:
            mainsr = subreddits[0]['subreddit']        

            lgndstr = "{0}::{1}".format(ngram, mainsr)

            data = get_timeseries_data(ngram, mainsr)
            x = [ k['date'] for k in data]
            y = [k['count'] for k in data]
            y2 = [k['percentage'] for k in data]
        else:
            x = Xtime
            y = [0] * len(Xtime)
            y2 = y
            lgndstr = ngram
        lgnd.append(lgndstr)
        XX.append(x)
        YY.append(y)
        YY2.append(y2)
        cnt +=1
        source.append(dict(xx = [datetime.strftime(kk, "%Y-%m") for kk in x], yy = y, desc = [lgndstr] * len(x)))

    #Creating figure box
    fig = figure(title="Trends (absolute count)", 
                 x_axis_label = "Time",
                 y_axis_label = "Word Count",
                 width=pwidth,
                 height=pheight, 
                 x_axis_type="datetime"
                 )
    
    #Plot the lines
    for k in range(cnt):
        fig.line(XX[k], YY[k], color=random.choice(colors), legend = lgnd[k], line_width=2)
    
    fig.legend.orientation = "top_left"

    fig2 = figure(title="Trends (ratio)", 
                 x_axis_label = "Time",
                 y_axis_label = "Ratio",
                 width=pwidth, 
                 height=pheight, 
                 x_axis_type="datetime"
                 )
    
    #Plot the lines
    for k in range(cnt):
        fig2.line(XX[k], YY2[k], color=random.choice(colors), legend = lgnd[k], line_width=2)
    
    fig2.legend.location = "top_left"
    
    p = hplot(fig, fig2)
    # Configure resources to include BokehJS inline in the document.
    # For more details see:
    js_resources = INLINE.render_js()
    css_resources = INLINE.render_css()

    script, div = components(p, INLINE)
    #script2, div2 = components(fig2, INLINE)
    html = render_template(
        'Ngram.html',
        plot_script=script,
        plot_div=div,
        js_resources=js_resources,
        css_resources=css_resources
        )

    return encode_utf8(html)
Example #42
0
affinity = cluster.AffinityPropagation(damping=.9, preference=-200)

# change here, to select clustering algorithm (note: spectral is slow)
algorithm = dbscan  # <- SELECT ALG

plots =[]
for dataset in (noisy_circles, noisy_moons, blobs1, blobs2):
    X, y = dataset
    X = StandardScaler().fit_transform(X)

    # predict cluster memberships
    algorithm.fit(X)
    if hasattr(algorithm, 'labels_'):
        y_pred = algorithm.labels_.astype(np.int)
    else:
        y_pred = algorithm.predict(X)

    p = Figure(webgl=True, title=algorithm.__class__.__name__,
               plot_width=PLOT_SIZE, plot_height=PLOT_SIZE)

    p.scatter(X[:, 0], X[:, 1], color=colors[y_pred].tolist(), alpha=0.1,)

    plots.append(p)

# generate layout for the plots
layout = vplot(hplot(*plots[:2]), hplot(*plots[2:]))

output_file("clustering.html", title="clustering with sklearn")

show(layout)
Example #43
0
         
         ICAmap_to_display.trigger('change');
         timeseries_to_display.trigger('change');
         ffts_to_display.trigger('change');
    """)

# Additional Code to link with time series
kappa_taptool = sp_kappa.select(type=TapTool)
kappa_taptool.callback = update_ts
rho_taptool = sp_rho.select(type=TapTool)
rho_taptool.callback = update_ts
var_taptool = sp_var.select(type=TapTool)
var_taptool.callback = update_ts
ratio_taptool = sp_ratio.select(type=TapTool)
ratio_taptool.callback = update_ts
kvr_taptool = sp_kvr.select(type=TapTool)
kvr_taptool.callback = update_ts

# ==============================================================================

# ==============================================================================
#                       GRAPH   LAYOUT
top_left = hplot(sp_tabs_kappa, sp_tabs_rho)
top_right = hplot(sp_tabs_var, sp_tabs_left)
top = hplot(top_left, top_right)
middle = hplot(sp_ts, sp_fft)
pl = vplot(comp_table_DTABLE, top, middle, ICAmapFigure)
p = hplot(pl)
show(p)
# ==============================================================================
def stop_handler():
    print("button_handler: stop click")
    global play
    play = False


play = True

button_start = Button(label="Start", type="success")
button_start.on_click(play_handler)

button_stop = Button(label="Stop", type="danger")
button_stop.on_click(stop_handler)

controls = hplot(button_start, button_stop)
layout = vplot(controls, p)

# Open the session in a browser
session.show(layout)

renderer = p.select(dict(name="sin"))
ds = renderer[0].data_source


def should_play():
    """Return true if we should play animation, otherwise block"""
    global play
    while True:
        if play:
            return True
Example #45
0
from viz import climate_map, timeseries, legend, get_slice  

# Data
data = netCDF4.Dataset('data/Land_and_Ocean_LatLong1.nc')
t = data.variables['temperature']

# Output option
output_server("climate")

# Plots
climate_map = climate_map()
timeseries = timeseries()
legend = legend()

# Create layout
map_legend = hplot(climate_map, legend)
layout = vplot(map_legend, timeseries)

# Show
show(layout)

# Select data source for climate_map
renderer = climate_map.select(dict(name="image"))
ds = renderer[0].data_source

# Create an infite loop to update image data
import time

while True:
   for year_index in np.arange(2000, 2015, 1):
        for month_index in np.arange(1, 13, 1):
x = [random() for x in range(500)]
y = [random() for y in range(500)]

s1 = ColumnDataSource(data=dict(x=x, y=y))
p1 = figure(plot_width=400, plot_height=400, tools="lasso_select", title="Select Here")
p1.circle("x", "y", source=s1, alpha=0.6)

s2 = ColumnDataSource(data=dict(x=[], y=[]))
p2 = figure(plot_width=400, plot_height=400, x_range=(0, 1), y_range=(0, 1), tools="", title="Watch Here")
p2.circle("x", "y", source=s2, alpha=0.6)

s1.callback = Callback(
    args=dict(s2=s2),
    code="""
        var inds = cb_obj.get('selected')['1d'].indices;
        var d1 = cb_obj.get('data');
        var d2 = s2.get('data');
        d2['x'] = []
        d2['y'] = []
        for (i = 0; i < inds.length; i++) {
            d2['x'].push(d1['x'][inds[i]])
            d2['y'].push(d1['y'][inds[i]])
        }
        s2.trigger('change');
    """,
)

layout = hplot(p1, p2)

show(layout)
def layout_components(map_plot, line_plot, text_box, key):
    detail = vplot(text_box, line_plot, key)
    mapbox = vplot(map_plot)
    composed = hplot(mapbox, detail)
    return composed
Example #48
0
            y[i] = data['y'][i]
        }

        txtData = txtSrc.get('data');
        txtData['text'][0] = 'speed: ' + data.speed
        txtMinData = txtMinSrc.get('data');
        txtMinData['text'][0] = 'minWL: ' + data.minwl
        txtMaxData = txtMaxSrc.get('data');
        txtMaxData['text'][0] = 'maxWL: ' + data.maxwl
});

        source.trigger('change');
        sPlot.trigger('change');
        txtSrc.trigger('change');
        txtMinSrc.trigger('change');
        txtMaxSrc.trigger('change');

    """)

sliderPDE.callback = callbackHist
sliderMinWL.callback = callbackHist
sliderASIC.callback = callbackHist
sliderSPTR.callback = callbackHist


sliders = hplot(sliderPDE,sliderMinWL,sliderASIC,sliderSPTR)
layout = vplot(vplot(sliders,hplot(ph,p2)), width=800, height=800)

output_file("scatter.html", title="color_scatter.py example")
show(layout)
Example #49
0
    def plot_scores(self, all_scores):

        if all_scores is None:
            return None

        scores = all_scores[0][:]
        scores = np.hstack((scores, np.mean(scores)))
        class_labels = self.class_labels[:]
        class_labels.append('average')
        data = {"precision": scores}
        s1 = Bar(data,
                 cat=class_labels,
                 title="Per Class Precision",
                 xlabel='categories',
                 ylabel='precision',
                 width=500,
                 height=500,
                 tools="pan,resize,box_zoom,hover,save,reset",
                 stacked=True,
                 palette=["#b2df8a"])

        hover = s1.select(dict(type=HoverTool))
        hover.tooltips = OrderedDict([
            ('precision', '@precision'),
        ])

        scores = all_scores[1][:]
        scores = np.hstack((scores, np.mean(scores)))
        class_labels = self.class_labels[:]
        class_labels.append('average')
        data = {"recall": scores}
        s2 = Bar(data,
                 cat=class_labels,
                 title="Per Class Recall",
                 xlabel='categories',
                 ylabel='recall',
                 width=500,
                 height=500,
                 tools="pan,resize,box_zoom,hover,save,reset",
                 stacked=True,
                 palette=["#a6cee3"])

        hover = s2.select(dict(type=HoverTool))
        hover.tooltips = OrderedDict([
            ('recall', '@recall'),
        ])

        data = {"support": all_scores[3]}
        s3 = Bar(data,
                 cat=self.class_labels,
                 title="Per Class Support",
                 xlabel='categories',
                 ylabel='support',
                 width=500,
                 height=500,
                 tools="pan,resize,box_zoom,hover,save,reset",
                 stacked=True,
                 palette=["#6a3d9a"])

        hover = s3.select(dict(type=HoverTool))
        hover.tooltips = OrderedDict([
            ('support', '@support'),
        ])

        p = hplot(s1, s2, s3)

        script, div = components(p)
        return (script, div)
Example #50
0
def fillCategories(category, state, csvFile):

    for x in range(len(state)):
        state[x] = unicodedata.normalize('NFKD',
                                         state[x]).encode('ascii', 'ignore')

    for x in range(len(category)):
        category[x] = unicodedata.normalize('NFKD', category[x]).encode(
            'ascii', 'ignore')

    #Dictionaries that will have state abbreviations as keys
    alcohol = {}
    arthritis = {}
    asthma = {}
    cancer = {}
    cardioVasc = {}
    chronicKidDis = {}
    chronObstPulDis = {}
    diabetes = {}
    disablitly = {}
    immunization = {}
    mentalHealth = {}
    fitnessAndHealth = {}
    olderAdults = {}
    oralHealth = {}
    overArchCon = {}
    reproductiveHealth = {}
    tobacco = {}

    # Initialize all state keys to 0
    for x in range(len(state)):
        alcohol[state[x]] = 0
        arthritis[state[x]] = 0
        asthma[state[x]] = 0
        cancer[state[x]] = 0
        cardioVasc[state[x]] = 0
        chronicKidDis[state[x]] = 0
        chronObstPulDis[state[x]] = 0
        diabetes[state[x]] = 0
        disablitly[state[x]] = 0
        immunization[state[x]] = 0
        mentalHealth[state[x]] = 0
        fitnessAndHealth[state[x]] = 0
        olderAdults[state[x]] = 0
        oralHealth[state[x]] = 0
        overArchCon[state[x]] = 0
        reproductiveHealth[state[x]] = 0
        tobacco[state[x]] = 0

    # Assings number of states with reported category diseases by iterating through CSV file
    # 17 in Total
    for row in range(len(csvFile)):

        if (csvFile['Category'][row] == category[0]
                and csvFile['LocationAbbr'][row] in state):
            alcohol[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[1]
              and csvFile['LocationAbbr'][row] in state):
            arthritis[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[2]
              and csvFile['LocationAbbr'][row] in state):
            asthma[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[3]
              and csvFile['LocationAbbr'][row] in state):
            cancer[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[4]
              and csvFile['LocationAbbr'][row] in state):
            cardioVasc[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[5]
              and csvFile['LocationAbbr'][row] in state):
            chronicKidDis[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[6]
              and csvFile['LocationAbbr'][row] in state):
            chronObstPulDis[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[7]
              and csvFile['LocationAbbr'][row] in state):
            diabetes[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[8]
              and csvFile['LocationAbbr'][row] in state):
            diabetes[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[9]
              and csvFile['LocationAbbr'][row] in state):
            immunization[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[10]
              and csvFile['LocationAbbr'][row] in state):
            mentalHealth[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[11]
              and csvFile['LocationAbbr'][row] in state):
            fitnessAndHealth[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[12]
              and csvFile['LocationAbbr'][row] in state):
            olderAdults[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[13]
              and csvFile['LocationAbbr'][row] in state):
            oralHealth[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[14]
              and csvFile['LocationAbbr'][row] in state):
            overArchCon[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[15]
              and csvFile['LocationAbbr'][row] in state):
            reproductiveHealth[csvFile['LocationAbbr'][row]] += 1

        elif (csvFile['Category'][row] == category[16]
              and csvFile['LocationAbbr'][row] in state):
            tobacco[csvFile['LocationAbbr'][row]] += 1

    choice = chooseCategory(category)
    customTitle = ""

    if (choice == 1):
        chosenCategory = alcohol
        customTitle = "Alchol"
    elif (choice == 2):
        chosenCategory = arthritis
        customTitle = "Arthritis"
    elif (choice == 3):
        chosenCategory = asthma
        customTitle = "Asthma"
    elif (choice == 4):
        chosenCategory = cancer
        customTitle = "Cancer"
    elif (choice == 5):
        chosenCategory = cardioVasc
        customTitle = "Cardio Vascular Disease"
    elif (choice == 6):
        chosenCategory = chronicKidDis
        customTitle = "Chronic Kidney Disease"
    elif (choice == 7):
        chosenCategory = chronObstPulDis
        customTitle = "Chronic Obstructive Pulmonary Disease"
    elif (choice == 8):
        chosenCategory = diabetes
        customTitle = "Diabetes"
    elif (choice == 9):
        chosenCategory = disablitly
        customTitle = "Disablilty"
    elif (choice == 10):
        chosenCategory = immunization
        customTitle = "Immunization"
    elif (choice == 11):
        chosenCategory = mentalHealth
        customTitle = "Mental Health"
    elif (choice == 12):
        chosenCategory = fitnessAndHealth
        customTitle = "Nutrition, Physical Activity, and Weight Status"
    elif (choice == 13):
        chosenCategory = olderAdults
        customTitle = "Older Adults"
    elif (choice == 14):
        chosenCategory = oralHealth
        customTitle = "Oral Health"
    elif (choice == 15):
        chosenCategory = overArchCon
        customTitle = "Overarching Conditions"
    elif (choice == 16):
        chosenCategory = reproductiveHealth
        customTitle = "Reproductive Health"
    elif (choice == 17):
        chosenCategory = tobacco
        customTitle = "Tobacco"
    else:
        chosenCategory = alcohol  # DEFAULT

    excluded = (
        'GU', 'PR', 'VI', 'US'
    )  # Excluding data with locations as United States or territories

    #Colors used to fill states
    colors = ["#DFAAAA", "#DD6666", "#B84544", "#944444", "#870000", "#490000"]
    #****************************************************************************
    # Will plot Alaska and Hawaii seperately for formatting purposes
    alaska = states['AK']
    alaska_state_x = [states['AK']["lons"]]
    alaska_state_y = [states['AK']["lats"]]
    hawaii = states['HI']
    hawaii_state_x = [states['HI']["lons"]]
    hawaii_state_y = [states['HI']["lats"]]

    alaska_color = ""
    hawaii_color = ""

    alaska_cases = chosenCategory['AK']
    hawaii_cases = chosenCategory['HI']

    # Alaska Cases
    if (alaska_cases < 20):
        alaska_color = colors[0]
    elif (alaska_cases < 40):
        alaska_color = colors[1]
    elif (alaska_cases < 60):
        alaska_color = colors[2]
    elif (alaska_cases < 80):
        alaska_color = colors[3]
    elif (alaska_cases < 100):
        alaska_color = colors[4]
    elif (alaska_cases >= 100):
        alaska_color = colors[5]
    else:
        alaska_color = "black"

    #Hawaii Cases
    if (hawaii_cases < 20):
        hawaii_color = colors[0]
    elif (hawaii_cases < 40):
        hawaii_color = colors[1]
    elif (hawaii_cases < 60):
        hawaii_color = colors[2]
    elif (hawaii_cases < 80):
        hawaii_color = colors[3]
    elif (hawaii_cases < 100):
        hawaii_color = colors[4]
    elif (hawaii_cases >= 100):
        hawaii_color = colors[5]
    else:
        hawaii_color = "black"
    #****************************************************************************

    del states['AK']  # Will only show the continental U.S.
    del states['HI']

    # Obtains the longitude and latitude for states in order to create map
    continental_state_xs = [states[code]["lons"] for code in states]
    continental_state_ys = [states[code]["lats"] for code in states]

    state_colors = []

    # Following for loop will assign a color to a state depending on number of cases
    for state_id in states:
        if state_id in excluded:
            continue
        try:
            cases = chosenCategory[state_id]
            #print ("Cases in %s" %state_id), ": " , cases
            if (cases >= 0 and cases < 20):
                state_colors.append(colors[0])
            elif (cases >= 21 and cases < 40):
                state_colors.append(colors[1])
            elif (cases >= 41 and cases < 60):
                state_colors.append(colors[2])
            elif (cases >= 61 and cases < 80):
                state_colors.append(colors[3])
            elif (cases >= 81 and cases < 100):
                state_colors.append(colors[4])
            elif (cases >= 100):
                state_colors.append(colors[5])
        except KeyError:
            state_colors.append("white")

    #***********************************************************************************************
    #Continental US glyphs and map
    continental_US = figure(title="US Chronic Diseases 2007-2013",
                            toolbar_location="left",
                            plot_width=1200,
                            plot_height=700)

    continental_US.circle(legend="0-20 Cases", color=colors[0])
    continental_US.circle(legend="21-40 Cases", color=colors[1])
    continental_US.circle(legend="41-60 Cases", color=colors[2])
    continental_US.circle(legend="61-80 Cases", color=colors[3])
    continental_US.circle(legend="81-100 Cases", color=colors[4])
    continental_US.circle(legend="100 or Greater Cases", color=colors[5])
    continental_US.circle(legend="No data recorded", color="white")

    continental_US.patches(continental_state_xs,
                           continental_state_ys,
                           fill_color=state_colors,
                           fill_alpha=100.0,
                           line_color="#884444",
                           line_width=2.5,
                           line_alpha=5.0)
    #***********************************************************************************************
    # Alaska Plot
    alaska_figure = figure(title="Alaska",
                           toolbar_location="left",
                           plot_width=5000,
                           plot_height=800)

    alaska_figure.circle(legend="0-20 Cases", color=colors[0])
    alaska_figure.circle(legend="21-40 Cases", color=colors[1])
    alaska_figure.circle(legend="41-60 Cases", color=colors[2])
    alaska_figure.circle(legend="61-80 Cases", color=colors[3])
    alaska_figure.circle(legend="81-100 Cases", color=colors[4])
    alaska_figure.circle(legend="100 or Greater Cases", color=colors[5])
    alaska_figure.circle(legend="No data recorded", color="white")

    alaska_figure.patches(alaska_state_x,
                          alaska_state_y,
                          fill_color=alaska_color,
                          fill_alpha=100.0,
                          line_color="#884444",
                          line_width=2.5,
                          line_alpha=5.0)
    #***********************************************************************************************
    # Hawaii Plot
    hawaii_figure = figure(title="Hawaii",
                           toolbar_location="left",
                           plot_width=900,
                           plot_height=1000)

    hawaii_figure.circle(legend="0-20 Cases", color=colors[0])
    hawaii_figure.circle(legend="21-40 Cases", color=colors[1])
    hawaii_figure.circle(legend="41-60 Cases", color=colors[2])
    hawaii_figure.circle(legend="61-80 Cases", color=colors[3])
    hawaii_figure.circle(legend="81-100 Cases", color=colors[4])
    hawaii_figure.circle(legend="100 or Greater Cases", color=colors[5])
    hawaii_figure.circle(legend="No data recorded", color="white")

    hawaii_figure.patches(hawaii_state_x,
                          hawaii_state_y,
                          fill_color=hawaii_color,
                          fill_alpha=100.0,
                          line_color="#884444",
                          line_width=2.5,
                          line_alpha=5.0)

    output_file("density.html", title=customTitle + " Cases")

    allFigures = hplot(continental_US, hawaii_figure, alaska_figure)

    show(allFigures)
Example #51
0
p.xaxis[0].formatter = xformatter


hover = p.select(dict(type=HoverTool))
hover.tooltips = OrderedDict([
    ("anomaly", "@anomaly"),
    ("time", "@time"),
])

hover.renderers = p.select("mva")


# Layout

layout = hplot(plot, legend_plot)
bottom = vplot(layout, p)

show(bottom)

renderer = plot.select(dict(name="im"))
ds = renderer[0].data_source

month_renderer = plot.select(dict(name="mo"))
month_ds = month_renderer[0].data_source

year_renderer = plot.select(dict(name="ye"))
year_ds = year_renderer[0].data_source

import time
Example #52
0
freq_slider = Slider(start=0.1,
                     end=10,
                     value=1,
                     step=.1,
                     title="Frequency",
                     callback=callback)
callback.args["freq"] = freq_slider

phase_slider = Slider(start=0,
                      end=6.4,
                      value=0,
                      step=.1,
                      title="Phase",
                      callback=callback)
callback.args["phase"] = phase_slider

offset_slider = Slider(start=-5,
                       end=5,
                       value=0,
                       step=.1,
                       title="Offset",
                       callback=callback)
callback.args["offset"] = offset_slider

layout = hplot(vform(amp_slider, freq_slider, phase_slider, offset_slider),
               plot)

output_file("slider.html")

show(layout)
Example #53
0
# set up callbacks
def on_selection_change(obj, attr, old, new):
    inds = np.array(new)
    if len(inds) == 0 or len(inds) == len(x):
        hhist = hzeros
        vhist = vzeros
        hhist2 = hzeros
        vhist2 = vzeros
    else:
        hhist, _ = np.histogram(x[inds], bins=hedges)
        vhist, _ = np.histogram(y[inds], bins=vedges)
        negative_inds = np.ones_like(x, dtype=np.bool)
        negative_inds[inds] = False
        hhist2, _ = np.histogram(x[negative_inds], bins=hedges)
        vhist2, _ = np.histogram(y[negative_inds], bins=vedges)

    ph_source.data["top"] = hhist
    pv_source.data["right"] = vhist
    ph_source2.data["top"] = -hhist2
    pv_source2.data["right"] = -vhist2

    cursession().store_objects(ph_source, pv_source, ph_source2, pv_source2)

scatter_ds.on_change('selected', on_selection_change)

layout = vplot(hplot(p, pv), hplot(ph, Paragraph()))
show(layout)

cursession().poll_document(curdoc(), 0.05)
Example #54
0
            x_range=(-vMax,vMax), y_range=scatterFig.y_range, title=None,
            min_border=10, min_border_top=toolbarHeight)
vFig.ygrid.grid_line_color=None
vFig.xaxis.major_label_orientation = -numpy.pi/2.0

vFig.quad(left=0, bottom=vEdges[:-1],top=hEdges[1:],right=vHist,color="white",line_color="blue")
#what are rhese? the selected and unselected points?
vh1=vFig.quad(left=0,bottom=vEdges[:-1],top=vEdges[1:],right=vZeros,alpha=0.5,**LINE_ARGS)
vh2=vFig.quad(left=0,bottom=vEdges[:-1],top=vEdges[1:],right=vZeros,alpha=0.1,**LINE_ARGS)

vFig.min_border_top=80
vFig.min_border_left=0
hFig.min_border_top=10
hFig.min_border_right=10
scatterFig.min_border_right=10
layout=vplot(hplot(scatterFig,vFig),hplot(hFig,Paragraph(width=200)),width=800,height=800)

def update(attr,old,new):
    inds=numpy.array(new['1d']['indices'])
    numpy.savetxt('testselect.txt',inds)
    if len(inds)==0 or len(inds)==len(x):
        hHist1,hHist2=hZeros,hZeros
        vHist1,vHist2=vZeros,vZeros
    else:
        negInds=numpy.ones_like(x,dtype=numpy.bool)
        negInds[inds]=False
        hHist1, _ =numpy.histogram(x[inds],bins=hEdges)
        vHist1, _ =numpy.histogram(y[inds],bins=vEdges)
        hHist2, _ =numpy.histogram(x[negInds],bins=hEdges)
        vHist2, _ =numpy.histogram(y[negInds],bins=vEdges)
    hh1.data_source.data["top"] = hHist1
Example #55
0
th = 42 # need to adjust for toolbar height, unfortunately
pv = figure(toolbar_location=None, plot_width=200, plot_height=p.plot_height+th-10, x_range=(-vmax, vmax),
            y_range=p.y_range, title=None, min_border=10, min_border_top=th)
pv.ygrid.grid_line_color = None
pv.xaxis.major_label_orientation = -3.14/2

pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vhist, color="white", line_color="#3A5785")
vh1 = pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vzeros, alpha=0.5, **LINE_ARGS)
vh2 = pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vzeros, alpha=0.1, **LINE_ARGS)

pv.min_border_top = 80
pv.min_border_left = 0
ph.min_border_top = 10
ph.min_border_right = 10
p.min_border_right = 10
layout = vplot(hplot(p, pv), hplot(ph, Paragraph(width=200)), width=800, height=800)

def update(attr, old, new):
    inds = np.array(new['1d']['indices'])
    if len(inds) == 0 or len(inds) == len(x):
        hhist1, hhist2 = hzeros, hzeros
        vhist1, vhist2 = vzeros, vzeros
    else:
        neg_inds = np.ones_like(x, dtype=np.bool)
        neg_inds[inds] = False
        hhist1, _ = np.histogram(x[inds], bins=hedges)
        vhist1, _ = np.histogram(y[inds], bins=vedges)
        hhist2, _ = np.histogram(x[neg_inds], bins=hedges)
        vhist2, _ = np.histogram(y[neg_inds], bins=vedges)

    hh1.data_source.data["top"]   =  hhist1
Example #56
0
         ICAmap_to_display.trigger('change');
         timeseries_to_display.trigger('change');
         ffts_to_display.trigger('change');
    """)

# Additional Code to link with time series
kappa_taptool          = sp_kappa.select(type=TapTool)
kappa_taptool.callback = update_ts 
rho_taptool            = sp_rho.select(type=TapTool)
rho_taptool.callback   = update_ts 
var_taptool            = sp_var.select(type=TapTool)
var_taptool.callback   = update_ts 
ratio_taptool          = sp_ratio.select(type=TapTool)
ratio_taptool.callback = update_ts 
kvr_taptool            = sp_kvr.select(type=TapTool)
kvr_taptool.callback   = update_ts


# ==============================================================================

# ==============================================================================
#                       GRAPH   LAYOUT
top_left  = hplot(sp_tabs_kappa, sp_tabs_rho)
top_right = hplot(sp_tabs_var, sp_tabs_left)
top       = hplot(top_left, top_right)
middle    = hplot(sp_ts, sp_fft)
pl        = vplot(comp_table_DTABLE,top, middle,ICAmapFigure)
p         = hplot(pl)
show(p)
# ==============================================================================
Example #57
0
def layout_components(map_plot, line_plot, text_box, key):
    detail = vplot(text_box, line_plot, key)
    mapbox = vplot(map_plot)
    composed = hplot(mapbox, detail)
    return composed
Example #58
0
                       y='y',
                       width=1,
                       height=10,
                       color='crcolor',
                       source=crsource)

# set up hover tool to show color hex code and sample swatch
p2.select_one(HoverTool).tooltips = [('color',
                                      '$color[hex, rgb, swatch]:crcolor'),
                                     ('RGB levels', '@RGBs')]

# theme everything for a cleaner look
curdoc().theme = Theme(json=yaml.load("""
attrs:
    Plot:
        toolbar_location: null
    Grid:
        grid_line_color: null
    Axis:
        axis_line_color: null
        major_label_text_color: null
        major_tick_line_color: null
        minor_tick_line_color: null
"""))

layout = hplot(vform(red_slider, green_slider, blue_slider), vform(p1, p2))

output_file("color_sliders.html")

show(layout)
    play = True


def stop_handler():
    print("button_handler: stop click")
    global play
    play = False


button_start = Button(label="Start", type="success")
button_start.on_click(play_handler)

button_stop = Button(label="Stop", type="danger")
button_stop.on_click(stop_handler)

controls = hplot(button_start, button_stop)

# In[6]:

# New circle in timeseries plot
timeseries.circle(x=[date],
                  y=[df[df.datetime == date].moving_average],
                  size=8,
                  name="circle")

# In[7]:

# Create layout
map_legend = hplot(climate_map, legend)
layout = vplot(controls, title, map_legend, timeseries)