def make_layout(): plot, source = make_plot() columns = [ TableColumn(field="dates", type="date", header="Date"), TableColumn(field="downloads", type="numeric", header="Downloads"), ] data_table = HandsonTable(source=source, columns=columns) 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 create_layout(self): #button = Button(label="Randomize data", type="success") #button.on_click(update_data) #top_panel = HBox(children=[button, self.harvest.plot, self.harvest.rate_plot]) top_panel = HBox(children=[self.harvest.plot, self.harvest.rate_plot]) domains = VBox(children=[ self.domain.sort_relevant_plot, self.domain.sort_crawled_plot, self.domain.sort_frontier_plot ], width=200) #middle_panel = HBox(children=[domains, handson.plot]) middle_panel = HBox(children=[domains]) layout = VBox(children=[top_panel, middle_panel]) self.layout = layout return layout
def make_ui(): plot, source = make_plot() columns = [ TableColumn(field="dates", type="date", header="Date"), TableColumn(field="downloads", type="numeric", header="Downloads"), ] data_table = HandsonTable(source=source, columns=columns) vbox = VBox(children=[plot, data_table]) return vbox
def 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_layout(self): from bokeh.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 create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ obj = cls() obj.pretext = PreText(text="", width=500, height=80) obj.inputs = VBoxForm() obj.outputs = VBox() #inputs obj.source = ColumnDataSource(data=dict(xs=[], ys=[])) obj.make_inputs() # outputs obj.make_data() obj.make_line_plot() obj.make_stats(err=None) obj.set_children() return obj
def root(): resources = Resources("inline") scatter = scatter_example() scatter_el = VBox(children=[HBox(children=[scatter])]) plot_script, plot_div = components(scatter_el, resources) plot_resources = RESOURCES.render( js_raw=resources.js_raw, css_raw=resources.css_raw, js_files=resources.js_files, css_files=resources.css_files, ) html = render_template("test.html", plot_resources=plot_resources, plot_script=plot_script, plot_div=plot_div) return encode_utf8(html)
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
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) plot.x_range = DataRange1d(sources=[line_source.columns("x")]) plot.y_range = DataRange1d(sources=[line_source.columns("y")]) 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)
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.add(vbox) session.store_document(document) if __name__ == "__main__": link = session.object_link(document.context) print("Please visit %s to see the plots" % link) view(link) session.poll_document(document)
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", header="Manufacturer", type="autocomplete", source=manufacturers), TableColumn(field="model", header="Model", type="autocomplete", source=models), TableColumn(field="displ", header="Displacement", type="numeric", format="0.00"), TableColumn(field="year", header="Year", type="numeric"), TableColumn(field="cyl", header="Cylinders", type="numeric"), TableColumn(field="trans", header="Transmission", type="dropdown", strict=True, source=transmissions), TableColumn(field="drv", header="Drive", type="autocomplete", strict=True, source=drives), TableColumn(field="class", header="Class", type="autocomplete", strict=True, source=classes), TableColumn(field="cty", header="City MPG", type="numeric"), TableColumn(field="hwy", header="Highway MPG", type="numeric"), ] handson_table = HandsonTable(source=self.source, columns=columns, sorting=True) xdr = DataRange1d(sources=[self.source.columns("index")]) #xdr = FactorRange(factors=manufacturers) ydr = DataRange1d( sources=[self.source.columns("cty"), self.source.columns("hwy")]) plot = Plot(title=None, data_sources=[self.source], 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(data_source=self.source, glyph=Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5)) hwy = Glyph(data_source=self.source, glyph=Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5)) select_tool = BoxSelectTool(renderers=[cty, hwy], select_y=False) plot.tools.append(select_tool) overlay = BoxSelectionOverlay(tool=select_tool) plot.renderers.extend([cty, hwy, ygrid, overlay]) 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, handson_table]) return layout
def create(cls): gbounds = cls.gbounds xmin, xmax, ymin, ymax = gbounds app = cls() data = ARDataSource( data_url="/bokeh/taxidata/pickup/", data=dict( x=[0], y=[0], dw=[xmax-xmin], dh=[ymax-ymin], palette=["Greys-256"] ) ) app.pickup_ar_plot_source = data plot = image(source=data, image="image", x="x", y="y", dw="dw", dh="dh", plot_width=400, plot_height=400, palette='palette', x_range=[xmin, xmax], y_range=[ymin, ymax], tools="pan,wheel_zoom,box_zoom,select,reset", title='pickup' ) plot.title_text_font='12pt' app.pickup_plot = plot app.pickup_raw_plot_source = plot.select({'type' : ColumnDataSource})[0] data = ARDataSource( data_url="/bokeh/taxidatavsregular/pickup/", data=dict( x=[0], y=[0], dw=[xmax-xmin], dh=[ymax-ymin], palette=["Greys-256"] ) ) app.pickup_comparison_ar_plot_source = data plot = image(source=data, image="image", x="x", y="y", dw="dw", dh="dh", plot_width=400, plot_height=400, palette='palette', x_range=[xmin, xmax], y_range=[ymin, ymax], tools="pan,wheel_zoom,box_zoom,select,reset", title='pickup comparison plot' ) plot.title_text_font='12pt' app.pickup_comparison_plot = plot app.pickup_comparison_raw_plot_source = plot.select({'type' : ColumnDataSource})[0] data = ARDataSource( data_url="/bokeh/taxidatavsregular/dropoff/", data=dict( x=[0], y=[0], dw=[xmax-xmin], dh=[ymax-ymin], palette=["Greys-256"] ) ) app.dropoff_comparison_ar_plot_source = data plot = image(source=data, image="image", x="x", y="y", dw="dw", dh="dh", plot_width=400, plot_height=400, palette='palette', x_range=[xmin, xmax], y_range=[ymin, ymax], tools="pan,wheel_zoom,box_zoom,select,reset", title='dropoff comparison plot' ) plot.title_text_font='12pt' app.dropoff_comparison_plot = plot app.dropoff_comparison_raw_plot_source = plot.select({'type' : ColumnDataSource})[0] data = ARDataSource( data_url="/bokeh/taxidata/dropoff/", data=dict( x=[0], y=[0], dw=[xmax-xmin], dh=[ymax-ymin], palette=["Greys-256"] ) ) app.dropoff_ar_plot_source = data plot = image(source=data, image="image", plot_width=400, plot_height=400, x="x", y="y", dw="dw", dh="dh", palette='palette', x_range=[xmin, xmax], y_range=[ymin, ymax], tools="pan,wheel_zoom,box_zoom,reset,select,reset", title='dropoff' ) plot.title_text_font='12pt' app.dropoff_plot = plot app.dropoff_raw_plot_source = plot.select({'type' : ColumnDataSource})[0] app.make_trip_distance_histogram() app.make_trip_time_histogram() app.widgets = VBoxForm() app.day_of_week_selector = Select.create( options=["-----", 'Weekday', 'Friday/Saturday/Sunday', 'Saturday/Sunday'], name='Day Of Week' ) app.date_slider = DateRangeSlider(value=(dt.datetime(2012, 1, 1), dt.datetime(2013, 1, 28)), bounds=(dt.datetime(2012, 12, 31), dt.datetime(2013, 1, 31)), step={'days' : 1}, range=({'days' : 1},{'days':30}), name='period', title='period' ) app.hour_selector = Select.create(options=["-----", '8am-12pm', '12pm-4pm', '4pm-8pm', '8pm-12am', '12am-4am'], name='Hour of the Day' ) title = Paragraph(text="NYC Taxi Cab Data", width=250, height=50) app.widgets.children=[title, app.date_slider, Paragraph(width=250, height=10), app.hour_selector, app.day_of_week_selector, Paragraph(width=250, height=10), app.distance_histogram, Paragraph(text="", width=250, height=50), app.time_histogram] app.images = VBox() app.regular = HBox() app.filtered = HBox() app.regular.children = [app.pickup_plot, app.dropoff_plot] app.filtered.children = [app.pickup_comparison_plot, app.dropoff_comparison_plot] app.images.children = [app.regular] app.children = [app.widgets, app.images] return app
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)
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") try: while True: session.load_document(document) time.sleep(0.5)
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