def create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ # create layout widgets obj = cls() obj.mainrow = HBox() obj.checkbox = VBox(height=50) obj.mapbox = VBox() #obj.bottomrow = HBox() obj.statsbox = VBox(width=500) obj.totalbox = VBox() obj.legendbox = HBox() labels = ["County Average Ratings", "Hotel Locations"] obj.make_inputs() obj.make_outputs() # outputs #obj.pretext = Paragraph(text="", width=500) obj.make_source() obj.make_county_source() lat = 39.8282 lng = -98.5795 zoom = 6 xr = Range1d() yr = Range1d() #obj.make_plots(lat, lng, zoom, xr, yr) obj.make_plots() # layout obj.set_children() return obj
def make_layout(): plot, source = make_plot() columns = [ TableColumn(field="dates", title="Date"), TableColumn(field="downloads", title="Downloads"), ] data_table = DataTable(source=source, columns=columns, width=400, height=400) button = Button(label="Randomize data", type="success") button.on_click(click_handler) buttons = VBox(children=[button]) vbox = VBox(children=[buttons, plot, data_table]) return vbox
def stock(ticker1, ticker2): pretext = PreText(text="", width=500) df = get_data(ticker1, ticker2) source = ColumnDataSource(data=df) source.tags = ['main_source'] p = figure( title="%s vs %s" % (ticker1, ticker2), plot_width=400, plot_height=400, tools="pan,wheel_zoom,box_select,reset", title_text_font_size="10pt", ) p.circle(ticker1 + "_returns", ticker2 + "_returns", size=2, nonselection_alpha=0.02, source=source) stats = df.describe() pretext.text = str(stats) row1 = HBox(children=[p, pretext]) hist1 = hist_plot(df, ticker1) hist2 = hist_plot(df, ticker2) row2 = HBox(children=[hist1, hist2]) line1 = line_plot(ticker1, source) line2 = line_plot(ticker2, source, line1.x_range) output = VBox(children=[row1, row2, line1, line2]) return output
def layout(): date_select = DateRangeSlider(name="period", title="Period:", value=(start, end), bounds=(bounds_start, bounds_end), value_labels='show', range=(dict(days=1), None)) date_select.on_change('value', on_date_change) country_select = Select(title="Host Site Country:", value="World", options=country_choices) country_select.on_change('value', on_country_change) controls = VBoxModelForm(_children=[ Paragraph(text="Date Range"), Paragraph(text=""), # spacing hack Paragraph(text=""), date_select, country_select ]) vboxsmall = VBoxModelForm(_children=[controls, source_par]) #hbox1 = HBox(children=[job_loc_plot_builder(), vboxsmall]) #hbox2 = HBox(children=[weekday_builder(), jobtype_builder()]) #layout = VBox(children=[hbox1, hbox2]) layout = VBox(children=[vboxsmall]) return layout
def groupEverything(sliders, dropdown, data_table): hboxes = groupSliders(sliders) inputs = VBox( children=[dropdown, hboxes[0], hboxes[1], hboxes[2], hboxes[3]], width=100, height=60) #hbox = HBox(children=[inputs, p]) vbox = VBoxForm(children=[inputs, data_table]) return vbox
def create_layout(): year_select = Select(title="Year:", value="2010", options=years) location_select = Select(title="Location:", value="World", options=locations) year_select.on_change('value', on_year_change) location_select.on_change('value', on_location_change) controls = HBox(children=[year_select, location_select]) layout = VBox(children=[controls, pyramid(), population()]) return layout
def create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ # create layout widgets obj = cls() obj.bigbox = VBox(width=670) obj.totalbox = HBox() obj.brandbox = VBox() obj.selectrbox = HBox() obj.make_source() # outputs obj.make_better_plots() obj.make_inputs() # layout obj.set_children() return obj
def set_children(self): self.input_frame = VBoxForm(children=[ self.min_excitation, self.max_excitation, self.min_emission, self.max_emission, self.chrom_class_select, ]) self.plot_frame = HBox(children=[self.plot]) self.top_frame = HBox(children=[self.plot_frame, self.input_frame]) self.table_frame = HBox(children=[self.data_table]) self.main_frame = VBox(children=[self.top_frame, self.table_frame]) self.children = [self.main_frame]
def create_layout(self): from bokeh.models.widgets import Select, HBox, VBox years = list(map(str, sorted(self.df.Year.unique()))) locations = sorted(self.df.Location.unique()) year_select = Select(title="Year:", value="2010", options=years) location_select = Select(title="Location:", value="World", options=locations) year_select.on_change('value', self.on_year_change) location_select.on_change('value', self.on_location_change) controls = HBox(year_select, location_select) self.layout = VBox(controls, self.plot)
def main(): state_xs, state_ys = get_us_state_outline() left, right = minmax(state_xs) bottom, top = minmax(state_ys) plot = Figure(title=TITLE, plot_width=1000, plot_height=700, tools="pan, wheel_zoom, box_zoom, reset", x_range=Range1d(left, right), y_range=Range1d(bottom, top), x_axis_label='Longitude', y_axis_label='Latitude') plot_state_outline(plot, state_xs, state_ys) density_overlay = DensityOverlay(plot, left, right, bottom, top) density_overlay.draw() grid_slider = Slider(title="Details", value=density_overlay.gridcount, start=10, end=100, step=10) grid_slider.on_change("value", density_overlay.grid_change_listener) radiance_slider = Slider(title="Min. Radiance", value=density_overlay.radiance, start=np.min(density_overlay.rad), end=np.max(density_overlay.rad), step=10) radiance_slider.on_change("value", density_overlay.radiance_change_listener) listener = ViewListener(plot, density_overlay, name="viewport") plot.x_range.on_change("start", listener) plot.x_range.on_change("end", listener) plot.y_range.on_change("start", listener) plot.y_range.on_change("end", listener) backends = ["CPU", "HSA"] default_value = backends[kde.USE_HSA] backend_select = Select(name="backend", value=default_value, options=backends) backend_select.on_change('value', density_overlay.backend_change_listener) doc = curdoc() doc.add(VBox(children=[plot, grid_slider, radiance_slider, backend_select])) doc.add_periodic_callback(density_overlay.periodic_callback, 0.5)
def create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ # create layout widgets obj = cls() obj.mainrow = HBox() obj.histrow = HBox() obj.statsbox = VBox() obj.input_box = VBoxForm() # create input widgets obj.make_inputs() # outputs obj.pretext = PreText(text="", width=500) obj.make_source() obj.make_plots() obj.make_stats() # layout obj.set_children() return obj
model = cluster.AgglomerativeClustering(linkage="average", affinity="cityblock", n_clusters=2, connectivity=connectivity) elif algorithm == 'Birch': model = cluster.Birch(n_clusters=2) elif algorithm == 'DBSCAN': model = cluster.DBSCAN(eps=.2) else: print('No Algorithm selected') model.fit(X) if hasattr(model, 'labels_'): y_pred = model.labels_.astype(np.int) else: y_pred = model.predict(X) colors = [Spectral6[i] for i in y_pred] source.data['colors'] = colors plot.title = algorithm dropdown.on_change('value', update_data) # SET UP LAYOUT inputs = HBox(children=[dropdown]) plots = HBox(children=[plot]) # add to document curdoc().add_root(VBox(children=[inputs, plots]))
patches_source = ColumnDataSource( dict(xs=[[X[i], X[i + 1], X[i + 1], X[i]] for i in range(len(X[:-1]))], ys=[[y0, y0, Y[i + 1], Y[i]] for i in range(len(Y[:-1]))], color=data.colors[:-1])) patches = Patches(xs="xs", ys="ys", fill_color="color", line_color="color") plot.add_glyph(patches_source, patches) line_source = ColumnDataSource(dict(x=data.dist, y=data.alt)) line = Line(x='x', y='y', line_color="black", line_width=1) plot.add_glyph(line_source, line) return plot data = prep_data(obiszow_mtb_xcm) trail = trail_map(data) altitude = altitude_profile(data) layout = VBox(children=[altitude, trail]) doc = Document() doc.add(layout) if __name__ == "__main__": filename = "trail.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Trail map and altitude profile")) print("Wrote %s" % filename) view(filename)
xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) plot.add_tools(HoverTool()) tab = Panel(child=plot, title=title) return tab def make_tabs(objs): return Tabs(tabs=[ make_tab(title, obj) for title, obj in objs ]) layout = VBox(children=[Paragraph(text="Only Image and ImageRGBA glyphs are not demonstrated."), make_tabs(glyphs), make_tabs(markers)]) doc = Document() doc.add_root(layout) if __name__ == "__main__": filename = "glyphs.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Glyphs")) print("Wrote %s" % filename) view(filename)
def __init__(self, X, y): """Initializes the data viewer args: - X: array of x,y data to plot - y: coloring data, length equal to number of (x,y) data pairs """ # normalize dataset for easier parameter selection self.X = StandardScaler().fit_transform(X) # estimate bandwidth for mean shift self.bandwidth = cluster.estimate_bandwidth(X, quantile=0.3) for i in range(4): self.colors[i] = [Spectral6[f] for f in y] self.source[i] = ColumnDataSource(data=dict( x=self.X[:, 0], y=self.X[:, 1], colors=self.colors[i])) # SET UP PLOT algorithm = 'Select Algorithm' tools = 'pan,wheel_zoom,box_select,reset' widgets_to_check_for_updates = [] #KMeans plot1 = Figure(plot_width=400, plot_height=400, title="KMeans", title_text_font_size='10pt', tools=tools) plot1.circle('x', 'y', fill_color='colors', line_color=None, source=self.source[0]) self.k_means_slider = Slider(start=1, end=20, value=2, step=1) widgets_to_check_for_updates.append(self.k_means_slider) plot2 = Figure(plot_width=400, plot_height=400, title="DBSCAN", title_text_font_size='10pt', tools=tools) plot2.circle('x', 'y', fill_color='colors', line_color=None, source=self.source[1]) self.DBSCAN_slider = Slider(start=0.01, end=1.0, step=0.01, value=0.2) widgets_to_check_for_updates.append(self.DBSCAN_slider) plot3 = Figure(plot_width=400, plot_height=400, title="Birch", title_text_font_size='10pt', tools=tools) plot3.circle('x', 'y', fill_color='colors', line_color=None, source=self.source[2]) self.birch_slider = Slider(start=1, end=20, value=2, step=1) widgets_to_check_for_updates.append(self.birch_slider) plot4 = Figure(plot_width=400, plot_height=400, title="Mean Shift", title_text_font_size='10pt', tools=tools) plot4.circle('x', 'y', fill_color='colors', line_color=None, source=self.source[3]) for widget in widgets_to_check_for_updates: widget.on_change('value', self.update_data) # SET UP LAYOUT self.plots = HBox(children=[ VBox(children=[ plot1, self.k_means_slider, plot3, self.birch_slider ]), VBox(children=[plot2, self.DBSCAN_slider, plot4]) ]) # add to document self.update_data('value', 0, 0)
stats.text = str(data[[t1, t2, t1+'_returns', t2+'_returns']].describe()) global layout h1 = get_histogram(t1) h2 = get_histogram(t2) layout.children[1] = HBox(h1, h2) ticker1.on_change('value', ticker1_change) ticker2.on_change('value', ticker2_change) def selection_change(attrname, old, new): t1, t2 = ticker1.value, ticker2.value data = get_data(t1, t2) selected = source.selected['1d']['indices'] if selected: data = data.iloc[selected, :] update_stats_and_histograms(data, t1, t2) source.on_change('selected', selection_change) # set up layout stats_box = VBox(stats) input_box = VBox(ticker1, ticker2) main_row = HBox(input_box, corr, stats_box) layout = VBox(main_row, HBox(), ts1, ts2) # initialize update() curdoc().add_root(layout)
corr.title = '%s returns vs. %s returns' % (t1, t2) ts1.title, ts2.title = t1, t2 def update_stats(data, t1, t2): stats.text = str(data[[t1, t2, t1+'_returns', t2+'_returns']].describe()) ticker1.on_change('value', ticker1_change) ticker2.on_change('value', ticker2_change) def selection_change(attrname, old, new): t1, t2 = ticker1.value, ticker2.value data = get_data(t1, t2) selected = source.selected['1d']['indices'] if selected: data = data.iloc[selected, :] update_stats(data, t1, t2) source.on_change('selected', selection_change) # set up layout stats_box = VBox(stats) input_box = VBox(ticker1, ticker2) main_row = HBox(input_box, corr, stats_box) layout = VBox(main_row, GridPlot(children=[[ts1], [ts2]])) # initialize update() curdoc().add_root(layout)
try: global expr expr = sy.sympify(new, dict(x=xs)) except (sy.SympifyError, TypeError, ValueError) as exception: dialog.content = str(exception) dialog.visible = True session.store_objects(dialog) else: update_data() dialog = Dialog(title="Invalid expression", buttons=["Close"]) slider = Slider(start=1, end=20, value=order, step=1, title="Order:") slider.on_change('value', on_slider_value_change) text = TextInput(value=str(expr), title="Expression:") text.on_change('value', on_text_value_change) inputs = HBox(children=[slider, text]) layout = VBox(children=[inputs, plot, dialog]) document.add(layout) update_data() if __name__ == "__main__": link = session.object_link(document.context) print("Please visit %s to see the plots" % link) view(link) print("\npress ctrl-C to exit") session.poll_document(document)
data = update_data() hist_plot('stock1', ticker1, h1source, data, plot=hist1) hist_plot('stock2', ticker2, h2source, data, plot=hist2) plot.title = '%s vs %s' % (ticker1, ticker2) line_plot1.title = ticker1 line_plot2.title = ticker2 def selection_change(attrname, old, new): df = get_data(ticker1, ticker2) if source.selected['1d']['indices']: selected_df = df.iloc[source.selected['1d']['indices'], :] else: selected_df = None hist_plot('stock1', ticker1, h1source, df, plot=hist1, selected_df=selected_df) hist_plot('stock2', ticker2, h2source, df, plot=hist2, selected_df=selected_df) ticker1_select.on_change('value', input1_change) ticker2_select.on_change('value', input2_change) source.on_change('selected', selection_change) # layout statsbox = VBox(children=[pretext]) input_box = VBox(children=[ticker1_select, ticker2_select]) mainrow = HBox(children=[input_box, plot, statsbox]) histrow = HBox(children=[hist1, hist2]) vbox = VBox(children=[mainrow, histrow, line_plot1, line_plot2]) curdoc().add(vbox)
mdssource.selected = [] session.store_objects(mdssource) btn_prev.on_click(on_btn_prev) btn_next.on_click(on_btn_next) btn_clear.on_click(on_btn_clear) slider = Slider(title="Slide to adjust relevance metric", value=0.25, start=0.0, end=1.0, step=0.01) topics = HBox(height=50, children=[btn_prev, btn_next, btn_clear]) metric = HBox(height=50, children=[slider]) left_panel = VBox(children=[topics, intertopic_distance_map]) right_panel = VBox(children=[metric, top_R_terms]) layout = HBox(children=[left_panel, right_panel]) document.add(layout) session.store_document(document) if __name__ == "__main__": link = session.object_link(document.context) print("Please visit %s to see the plots" % link) view(link) print("\npress ctrl-C to exit") session.poll_document(document)
fill_alpha=0.5, line_alpha=0.5) cty = GlyphRenderer(data_source=source, glyph=cty_glyph) hwy = GlyphRenderer(data_source=source, glyph=hwy_glyph) tooltips = [ ("Manufacturer", "@manufacturer"), ("Model", "@model"), ("Displacement", "@displ"), ("Year", "@year"), ("Cylinders", "@cyl"), ("Transmission", "@trans"), ("Drive", "@drv"), ("Class", "@class"), ] cty_hover_tool = HoverTool(plot=plot, renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")]) hwy_hover_tool = HoverTool(plot=plot, renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")]) select_tool = BoxSelectTool(plot=plot, renderers=[cty, hwy], dimensions=['width']) plot.tools.extend([cty_hover_tool, hwy_hover_tool, select_tool]) plot.renderers.extend([cty, hwy, ygrid]) # }}} layout = VBox(plot, data_table) show(layout)
cluster.Birch(n_clusters=self.birch_slider.value), cluster.MeanShift(bandwidth=self.bandwidth, bin_seeding=True) ] #AgglomerativeClustering assert len(models) == 4 for model in models: model.fit(self.X) for i in range(4): if hasattr(model, 'labels_'): y_pred = models[i].labels_.astype(np.int) else: y_pred = models[i].predict(self.X) self.colors[i] = [Spectral6[f % 6] for f in y_pred] self.source[i].data['colors'] = self.colors[i] # SET UP DATA np.random.seed(0) n_samples = 1500 # Noisy circles dataset X, y = datasets.make_circles(n_samples=n_samples, factor=.5, noise=.05) #X = data point, y = group of each data point curdoc().add_root(VBox(children=[VisualDataClustering(X, y).get_plots()]))
("Displacement", "@displ"), ("Year", "@year"), ("Cylinders", "@cyl"), ("Transmission", "@trans"), ("Drive", "@drv"), ("Class", "@class"), ] cty_hover_tool = HoverTool(plot=plot, renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")]) hwy_hover_tool = HoverTool(plot=plot, renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")]) select_tool = BoxSelectTool(plot=plot, renderers=[cty, hwy], dimensions=['width']) plot.tools.extend([cty_hover_tool, hwy_hover_tool, select_tool]) plot.renderers.extend([cty, hwy, ygrid]) layout = VBox(children=[plot, data_table]) doc = Document() doc.add(layout) if __name__ == "__main__": filename = "data_tables.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Data Tables")) print("Wrote %s" % filename) view(filename)
xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) tab = Panel(child=plot, title=title) return tab def make_tabs(objs): return Tabs(tabs=[make_tab(title, obj) for title, obj in objs]) layout = VBox(children=[make_tabs(glyphs), make_tabs(markers)]) doc = Document() doc.add(layout) if __name__ == "__main__": filename = "glyphs.html" with open(filename, "w") as f: f.write(file_html(doc, INLINE, "Glyphs")) print("Wrote %s" % filename) view(filename)
def create(self): manufacturers = sorted(mpg["manufacturer"].unique()) models = sorted(mpg["model"].unique()) transmissions = sorted(mpg["trans"].unique()) drives = sorted(mpg["drv"].unique()) classes = sorted(mpg["class"].unique()) manufacturer_select = Select(title="Manufacturer:", value="All", options=["All"] + manufacturers) manufacturer_select.on_change('value', self.on_manufacturer_change) model_select = Select(title="Model:", value="All", options=["All"] + models) model_select.on_change('value', self.on_model_change) transmission_select = Select(title="Transmission:", value="All", options=["All"] + transmissions) transmission_select.on_change('value', self.on_transmission_change) drive_select = Select(title="Drive:", value="All", options=["All"] + drives) drive_select.on_change('value', self.on_drive_change) class_select = Select(title="Class:", value="All", options=["All"] + classes) class_select.on_change('value', self.on_class_change) columns = [ TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")), TableColumn(field="model", title="Model", editor=StringEditor(completions=models)), TableColumn(field="displ", title="Displacement", editor=NumberEditor(step=0.1), formatter=NumberFormatter(format="0.0")), TableColumn(field="year", title="Year", editor=IntEditor()), TableColumn(field="cyl", title="Cylinders", editor=IntEditor()), TableColumn(field="trans", title="Transmission", editor=SelectEditor(options=transmissions)), TableColumn(field="drv", title="Drive", editor=SelectEditor(options=drives)), TableColumn(field="class", title="Class", editor=SelectEditor(options=classes)), TableColumn(field="cty", title="City MPG", editor=IntEditor()), TableColumn(field="hwy", title="Highway MPG", editor=IntEditor()), ] data_table = DataTable(source=self.source, columns=columns, editable=True) xdr = DataRange1d() ydr = DataRange1d() plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=300) xaxis = LinearAxis(plot=plot) plot.below.append(xaxis) yaxis = LinearAxis(plot=plot) ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker) plot.left.append(yaxis) cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5) hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5) cty = GlyphRenderer(data_source=self.source, glyph=cty_glyph) hwy = GlyphRenderer(data_source=self.source, glyph=hwy_glyph) tooltips = [ ("Manufacturer", "@manufacturer"), ("Model", "@model"), ("Displacement", "@displ"), ("Year", "@year"), ("Cylinders", "@cyl"), ("Transmission", "@trans"), ("Drive", "@drv"), ("Class", "@class"), ] cty_hover_tool = HoverTool(plot=plot, renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")]) hwy_hover_tool = HoverTool(plot=plot, renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")]) select_tool = BoxSelectTool(plot=plot, renderers=[cty, hwy], dimensions=['width']) plot.tools.extend([cty_hover_tool, hwy_hover_tool, select_tool]) plot.renderers.extend([cty, hwy, ygrid]) controls = VBox(children=[ manufacturer_select, model_select, transmission_select, drive_select, class_select ], width=200) top_panel = HBox(children=[controls, plot]) layout = VBox(children=[top_panel, data_table]) return layout
default_value="baz") split.on_click(split_handler) checkbox_group = CheckboxGroup(labels=["Option 1", "Option 2", "Option 3"], active=[0, 1]) checkbox_group.on_click(checkbox_group_handler) radio_group = RadioGroup(labels=["Option 1", "Option 2", "Option 3"], active=0) radio_group.on_click(radio_group_handler) checkbox_button_group = CheckboxButtonGroup( labels=["Option 1", "Option 2", "Option 3"], active=[0, 1]) checkbox_button_group.on_click(checkbox_button_group_handler) radio_button_group = RadioButtonGroup( labels=["Option 1", "Option 2", "Option 3"], active=0) radio_button_group.on_click(radio_button_group_handler) vbox = VBox(children=[ button, toggle, dropdown, split, checkbox_group, radio_group, checkbox_button_group, radio_button_group ]) document = Document() document.add_root(vbox) session = push_session(document) session.show() if __name__ == "__main__": session.loop_until_closed()
colors = [spectral[i] for i in y_pred] source.data['x'] = X[:, 0] source.data['y'] = X[:, 1] source.data['colors'] = colors def update_clusters(attrname, old, new): algorithm = algorithm_select.value n_clusters = int(clusters_slider.value) n_samples = int(samples_slider.value) global X X, y_pred = clustering(X, algorithm, n_clusters) colors = [spectral[i] for i in y_pred] source.data['x'] = X[:, 0] source.data['y'] = X[:, 1] source.data['colors'] = colors algorithm_select.on_change('value', update_algorithm) dataset_select.on_change('value', update_dataset) clusters_slider.on_change('value', update_clusters) samples_slider.on_change('value', update_samples) # SET UP LAYOUT sliders = VBox(children=[samples_slider, clusters_slider]) selects = HBox(children=[dataset_select, algorithm_select]) inputs = VBox(children=[sliders, selects]) plots = HBox(children=[plot]) # add to document curdoc().add_root(HBox(children=[inputs, plots]))
print "/////////////////////////////////////////////////////" print argspec print argspec.args print temp_chillun print "/////////////////////////////////////////////////////" #clustering_options = HBox(children=[options]) model.fit(X) if hasattr(model, 'labels_'): y_pred = model.labels_.astype(np.int) else: y_pred = model.predict(X) colors = [Spectral6[i] for i in y_pred] source.data['colors'] = colors plot.title = algorithm dropdown.on_change('value', update_data) # SET UP LAYOUT clustering_options = VBox(*temp_chillun) inputs = HBox(children=[dropdown]) plots = HBox(children=[plot]) # add to document curdoc().add_root(VBox(children=[inputs, plots, clustering_options])) update_data()
def make_spectrogram(): plot_kw = dict(tools="", min_border=1, h_symmetry=False, v_symmetry=False, toolbar_location=None) freq = VBox(children=[ Paragraph(text="Freq Range"), Slider(orientation="vertical", start=1, end=MAX_FREQ, value=MAX_FREQ, step=1, name="freq") ]) gain = VBox(children=[ Paragraph(text="Gain"), Slider(orientation="vertical", start=1, end=20, value=1, step=1, name="gain") ]) spec_source = ColumnDataSource(data=dict(image=[], x=[])) spec = image_rgba(x='x', y=0, image='image', dw=TILE_WIDTH, dh=MAX_FREQ, cols=TILE_WIDTH, rows=SPECTROGRAM_LENGTH, title=None, source=spec_source, plot_width=800, plot_height=300, x_range=[0, NGRAMS], y_range=[0, MAX_FREQ], dilate=True, name="spectrogram", **plot_kw) spectrum_source = ColumnDataSource(data=dict(x=[], y=[])) spectrum = line(x="x", y="y", line_color="darkblue", title="Power Spectrum", source=spectrum_source, plot_width=800, plot_height=250, x_range=[0, MAX_FREQ], y_range=[10**(-4), 10**3], y_axis_type="log", name="spectrum", **plot_kw) signal_source = ColumnDataSource(data=dict(x=[], y=[])) signal = line(x="x", y="y", line_color="darkblue", title="Signal", source=signal_source, plot_width=800, plot_height=250, x_range=[0, TIMESLICE * 1.01], y_range=[-0.1, 0.1], name="signal", **plot_kw) radial_source = ColumnDataSource(data=dict( inner_radius=[], outer_radius=[], start_angle=[], end_angle=[], fill_alpha=[], )) eq = annular_wedge(x=0, y=0, fill_color="#688AB9", fill_alpha="fill_alpha", line_color=None, inner_radius="inner_radius", outer_radius="outer_radius", start_angle="start_angle", end_angle="end_angle", title=None, source=radial_source, plot_width=500, plot_height=520, x_range=[-20, 20], y_range=[-20, 20], name="eq", **plot_kw) grid().grid_line_color = None lines = VBox(children=[spectrum, signal]) layout = VBox(children=[ HBox(children=[freq, gain, spec]), HBox(children=[lines, eq]) ]) return layout