def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.add_tools( CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) button = Toggle(css_classes=['foo']) def cb(value): if value: source.data = dict(x=[10, 20], y=[10, 10]) else: source.data = dict(x=[100, 200], y=[100, 100]) button.on_click(cb) doc.add_root(column(button, plot))
def _setup_graph_renderer(self, circle_size): # The renderer will have the actual logic for drawing graph_renderer = GraphRenderer() # Add the vertex data as instructions for drawing nodes graph_renderer.node_renderer.data_source.add( list(self.graph.vertices.keys()), "index" ) # Nodes will be random colors graph_renderer.node_renderer.data_source.add(self._get_random_colors(), "color") # And circles graph_renderer.node_renderer.glyph = Circle( size=circle_size, fill_color="color" ) # Add the edge [start, end] indices as instructions for drawing edges graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes() self.randomize() # Randomize vertex coordinates, and set as layout graph_renderer.layout_provider = StaticLayoutProvider(graph_layout=self.pos) # Attach the prepared renderer to the plot so it can be shown self.plot.renderers.append(graph_renderer)
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y')) plot.add_tools( CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) colorpicker = ColorPicker(color='red', css_classes=["foo"]) def cb(attr, old, new): source.data['val'] = [old.lower(), new.lower()] # ensure lowercase of hexa strings colorpicker.on_change('color', cb) doc.add_root(column(colorpicker, plot)) return doc
def add_legend(plot): plot = add_circles(plot) # Add a custom legend text_x = 7 text_y = 95 for i, region in enumerate(regions): plot.add_glyph( Text(x=text_x, y=text_y, text=[region], text_font_size='10pt', text_color='#666666')) plot.add_glyph( Circle(x=text_x - 0.1, y=text_y + 2, fill_color=Spectral6[i], size=10, line_color=None, fill_alpha=0.8)) text_y = text_y - 5 return plot
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"])) plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.tags.append( CustomJS(name="custom-action", args=dict(s=source), code=RECORD("data", "s.data"))) def cb(attr, old, new): source.data['val'] = [ slider.value_as_date[0].isoformat(), slider.value_as_date[1].isoformat() ] slider.on_change('value', cb) doc.add_root(column(slider, plot))
def _setup_graph_renderer(self, circle_size): graph_renderer = GraphRenderer() node_indices = [*self.graph.vertices.keys()] colors = [self.graph.vertices[i].color for i in node_indices] alphas = [0.8 for _ in node_indices] print(colors) graph_renderer.node_renderer.data_source.data = dict( index=node_indices, fill_color=colors, fill_alpha=alphas) graph_renderer.node_renderer.glyph = Circle(size=circle_size, fill_color='fill_color', fill_alpha='fill_alpha') graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes( ) self.randomize() graph_renderer.layout_provider = StaticLayoutProvider( graph_layout=self.pos) self.plot.renderers.append(graph_renderer)
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.tags.append( CustomJS(name="custom-action", args=dict(s=source), code=RECORD("data", "s.data"))) def cb(event): if button.active: source.data = dict(x=[10, 20], y=[10, 10]) else: source.data = dict(x=[100, 200], y=[100, 100]) button.on_event('button_click', cb) doc.add_root(column(button, plot))
def modify_doc(doc): data = {"xs": [[1, 2], [1.6, 2.45]], "ys": [[1, 1], [1.5, 0.75]]} source = ColumnDataSource(data) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0) renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys')) tool = PolyEditTool(renderers=[renderer]) psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool plot.toolbar_sticky = False div = Div(text='False') def cb(attr, old, new): if cds_data_almost_equal(new, expected): div.text = 'True' source.on_change('data', cb) code = RECORD("matches", "div.text") plot.add_tools(CustomAction(callback=CustomJS(args=dict(div=div), code=code))) doc.add_root(column(plot, div))
def test_clicking_resets_selection(self, single_plot_page) -> None: source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) source.selected.indices = [0] source.selected.line_indices = [0] # XXX (bev) string key for multiline_indices seems questionable source.selected.multiline_indices = {"0": [0]} plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.add_tools(ResetTool()) code = \ RECORD("indices", "s.selected.indices") + \ RECORD("line_indices", "s.selected.line_indices") + \ RECORD("multiline_indices", "s.selected.multiline_indices") plot.add_tools(CustomAction(callback=CustomJS(args=dict(s=source), code=code))) plot.toolbar_sticky = False page = single_plot_page(plot) # Verify selections are non empty page.click_custom_action() results = page.results assert results['indices'] == [0] assert results['line_indices'] == [0] assert results['multiline_indices'] == {"0": [0]} # XXX (bev) string key # Click the reset tool and check the selections are restored button = page.get_toolbar_button('reset') button.click() page.click_custom_action() results = page.results assert results['indices'] == [] assert results['line_indices'] == [] assert results['multiline_indices'] == {} assert page.has_no_console_errors()
def render_from_fb_combined(): print('rendering from facebook_combined.txt') df = pd.read_csv('facebook_combined.txt', sep=" ", header=None) G = nx.from_pandas_edgelist(df.head(1000), 0, 1) print(nx.info(G)) plot = Plot(background_fill_color="white", sizing_mode="stretch_both", x_range=Range1d(-0.5, 0.5), y_range=Range1d(-0.5, 0.5)) graph_renderer = from_networkx( G, nx.spring_layout, scale=1, center=(0, 0)) graph_renderer.node_renderer.glyph = Circle( size=15, fill_color=Spectral4[0]) graph_renderer.edge_renderer.glyph = MultiLine( line_alpha=0.8, line_width=1) plot.add_tools(WheelZoomTool()) plot.add_tools(ResetTool()) plot.add_tools(PanTool()) plot.add_tools(HoverTool( tooltips=[("user", "datracka"), ("url", "https://twitter.com/datracka")])) plot.add_tools(PointDrawTool( renderers=[], empty_value='black')) plot.axis.axis_line_width = 0 plot.grid.grid_line_width = 0 plot.xaxis.major_tick_line_color = None # turn off x-axis major ticks plot.xaxis.minor_tick_line_color = None # turn off x-axis minor ticks plot.yaxis.major_tick_line_color = None # turn off y-axis major ticks plot.yaxis.minor_tick_line_color = None # turn off y-axis minor ticks plot.xaxis.major_label_text_color = None # Remove label x axis plot.yaxis.major_label_text_color = None # Remove label x axis plot.border_fill_color = None plot.outline_line_color = None plot.renderers.append(graph_renderer) return plot
def _make_plot(): data = {"xs": [[1, 2], [1.6, 2.45]], "ys": [[1, 1], [1.5, 0.75]]} source = ColumnDataSource(data) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0) renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys', line_width=10)) tool = PolyEditTool(renderers=[renderer]) psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys") plot.add_tools( CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def mapPlotter(data): map_options = GMapOptions(lat=41, lng=12, map_type="hybrid", zoom=4) plot = GMapPlot( x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, plot_width=1000, plot_height=500, ) plot.title.text = "Our wines!" hover = HoverTool(tooltips=[ ("Winery", "@Winery"), ("Wine Name", "@wineName"), ]) # For GMaps to function, Google requires you obtain and enable an API key: # # https://developers.google.com/maps/documentation/javascript/get-api-key # # Replace the value below with your personal API key: plot.api_key = plot_Api_Key source_map = ColumnDataSource(data) circle = Circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.5, line_color=None) plot.add_glyph(source_map, circle) plot.add_tools(hover, PanTool(), WheelZoomTool(), BoxSelectTool(), BoxZoomTool(), ResetTool(), ZoomInTool()) # output_file("gmap_plot.html") # show(plot) return plot
def map_data(): df0 = pd.read_csv( 'df_clean.csv', index_col=0) # need to tell pandas the first row is an index column df = df0.groupby('city').mean() # gives us the MEAN PRICE FOR EACH CITY # print(df.head) # Google maps has control over plot axes so no DataRange1d, only Range1d map_options = GMapOptions( lat=50.5020794, lng=-111.9912878, map_type='satellite', zoom=3) # LAT LNG ARE ROUGHLY THE CENTER OF THE MAP plot = GMapPlot(x_range=Range1d(), y_range=Range1d(), map_options=map_options, api_key=api_key) plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool()) # ranges for our circles in bokeh (gliphs) baseline = df['price'].min() - 1.0 # smallest price is smallest dot scale = 10.4 # latitude and longitude for the circles (gliphs) on the map, dict in this column format # radius is scaling, i is price, subtracting baseline by a scale so the circles fit source = ColumnDataSource(data=dict(lat=df['lat'].tolist(), lon=df['lng'].tolist(), rad=[(i - baseline) / scale for i in df['price'].tolist()])) circle = Circle(x="lon", y="lat", size="rad", fill_color="blue", fill_alpha=0.5) # alpha makes transparent plot.add_glyph(source, circle) # print(plot.add_glyph(source, circle) output_file('USA_plot.html') show(plot)
def show(self): graph = GraphRenderer() node_indices = list(self.graph.vertices.keys()) n = len(node_indices) plot = figure(x_range=(0, 10), y_range=(0, 10)) graph.node_renderer.data_source.add(node_indices, 'index') graph.node_renderer.data_source.add(Spectral8, 'color') graph.node_renderer.glyph = Circle(radius=0.1, fill_color='color') graph.edge_renderer.data_source.data = dict(start=[0] * n, end=node_indices) x = [i for i in range(n)] y = [j for j in range(n)] graph_layout = dict(zip(node_indices, zip(x, y))) graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout) plot.renderers.append(graph) output_file('graph.html') show(plot)
def render_kb(name, entity, attribute): if attribute is None: N = 0 else: N = len(attribute) node_indices = list(range(N+1)) plot = Plot(plot_width=2000, plot_height=2000, x_range=Range1d(-1.1, 1.1), y_range=Range1d(-1.1, 1.1)) plot.add_tools(PanTool()) plot.add_tools(ZoomInTool()) plot.title.text = name graph = GraphRenderer() graph.node_renderer.data_source.add(node_indices, 'index') graph.node_renderer.glyph = Circle(size=50, fill_color=Spectral4[0]) graph.edge_renderer.data_source.data = dict( start=[0]*N, end=node_indices[1:]) circ = [i*2*math.pi/N for i in range(N)] r = [random.random() for i in circ] for i,x in enumerate(r): if x < 0.3: r[i]+= 0.3 x = [0]+[math.cos(c)*r[i] for i,c in enumerate(circ)] y = [0]+[math.sin(c)*r[i] for i,c in enumerate(circ)] graph_layout = dict(zip(node_indices, zip(x, y))) graph.layout_provider = StaticLayoutProvider(graph_layout=graph_layout) attribute = [entity] + attribute source = ColumnDataSource({'x': x, 'y': y, 'txt': [ attribute[i] for i in range(len(attribute))]}) labels = LabelSet(x='x', y='y', text='txt', x_offset=-20, y_offset=-15, source=source,text_font_size='18pt', background_fill_color='white') plot.renderers.append(labels) plot.renderers.append(graph) return plot
def plot_circles( mol_plot: figure, source: ColumnDataSource, categorical_colour: bool = False, factors: Optional[List[Any]] = None, colormap=palettes.Category10_10, ) -> figure: """Add the points to a bokeh figure to render the trimer molecule. This enables the trimer molecules to be drawn on the figure using only the position and the orientations of the central molecule. """ glyph_args = dict( x="x", y="y", fill_alpha=1, line_alpha=0, radius="radius", fill_color="colour" ) if categorical_colour: if factors is None: factors = np.unique(source.data["colour"]).astype(str) colour_categorical = factor_cmap( field_name="colour", factors=factors, palette=colormap ) glyph_args["fill_color"] = colour_categorical glyph = Circle(**glyph_args) mol_plot.add_glyph(source, glyph=glyph) mol_plot.add_tools( HoverTool( tooltips=[ ("index", "$index"), ("x:", "@x"), ("y:", "@y"), ("orientation:", "@orientation"), ] ) ) mol_plot.toolbar.active_inspect = None return mol_plot
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_tools( CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) plot.add_glyph(source, Circle(x='x', y='y', size=20)) dp = DatePicker(title='Select date', value=datetime(2019, 9, 20), min_date=datetime(2019, 9, 1), max_date=datetime.utcnow(), css_classes=["foo"]) def cb(attr, old, new): source.data['val'] = [old, new] dp.on_change('value', cb) doc.add_root(column(dp, plot))
def plot_restaurant_map(data, y): df = yelp_businesses_to_dataframe(data, y) plot = GMapPlot( api_key=GOOGLE_API_KEY, x_range=Range1d(), y_range=Range1d(), map_options=GMapOptions( lat=40.735, lng=-73.990, map_type="roadmap", zoom=13, ), ) plot.toolbar.logo = None plot.toolbar_location = 'above' plot.title.text = "NYC restaurant sample ({:,})".format(len(df)) plot.add_tools( PanTool(), BoxZoomTool(), BoxSelectTool(), WheelZoomTool(), ResetTool(), SaveTool(), ) source = ColumnDataSource(data=df[['lat', 'lon', 'catcolor', 'revsize']], ) circle = Circle( x="lon", y="lat", line_color='black', fill_color='catcolor', fill_alpha=0.8, size='revsize', ) plot.add_glyph(source, circle) output_file("plots/restaurant_plot.html") show(plot)
def test_low_high(self, single_plot_page: SinglePlotPage) -> None: source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) num_input = NumericInput(value=4, low=-1, high=10) num_input.js_on_change('value', CustomJS(code=RECORD("value", "cb_obj.value"))) page = single_plot_page(column(num_input, plot)) el = find_element_for(page.driver, num_input, "input") assert el.get_attribute('value') == "4" enter_text_in_element(page.driver, el, "30", click=2) assert el.get_attribute('value') == "10" enter_text_in_element(page.driver, el, "-10", click=2) assert el.get_attribute('value') == "-1"
def _setup_graph_renderer(self, circle_size, draw_components): # The renderer will have the actual logic for drawing graph_renderer = GraphRenderer() # Saving vertices in an arbitrary but persistent order self.vertex_keys = list(self.graph.vertices.keys()) # Add the vertex data as instructions for drawing nodes graph_renderer.node_renderer.data_source.add([vertex.label for vertex in self.vertex_keys], 'index') colors = (self._get_connected_component_colors() if draw_components else self._get_random_colors()) graph_renderer.node_renderer.data_source.add(colors, 'color') # And circles graph_renderer.node_renderer.glyph = Circle(size=circle_size, fill_color='color') # Add the edge [start, end] indices as instructions for drawing edges graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes() self.randomize() # Randomize vertex coordinates, and set as layout graph_renderer.layout_provider = StaticLayoutProvider( graph_layout=self.pos) # Attach the prepared renderer to the plot so it can be shown self.plot.renderers.append(graph_renderer)
def _make_plot(num_objects=0, drag=True, vertices=False): source = ColumnDataSource(dict(xs=[[1, 2]], ys=[[1, 1]])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0) renderer = plot.add_glyph(source, MultiLine(xs='xs', ys='ys')) tool = PolyDrawTool(num_objects=num_objects, drag=drag, renderers=[renderer]) if vertices: psource = ColumnDataSource(dict(x=[], y=[])) prenderer = plot.add_glyph(psource, Circle(x='x', y='y', size=10)) tool.vertex_renderer = prenderer plot.add_tools(tool) plot.toolbar.active_multi = tool code = RECORD("xs", "source.data.xs") + RECORD("ys", "source.data.ys") plot.add_tools( CustomAction(callback=CustomJS(args=dict(source=source), code=code))) plot.toolbar_sticky = False return plot
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 3), y_range=Range1d(0, 3), min_border=0) renderer = plot.add_glyph(source, Circle(x='x', y='y')) tool = PointDrawTool(renderers=[renderer]) plot.add_tools(tool) plot.toolbar.active_multi = tool div = Div(text='False') def cb(attr, old, new): if cds_data_almost_equal(new, expected): div.text = 'True' source.on_change('data', cb) code = RECORD("matches", "div.text") plot.add_tools( CustomAction(callback=CustomJS(args=dict(div=div), code=code))) doc.add_root(column(plot, div))
def _setup_graph_renderer(self, circle_size, draw_components): graph_renderer = GraphRenderer() self.vertex_keys = list(self.graph.vertices.keys()) graph_renderer.node_renderer.data_source.add( [vertex.label for vertex in self.vertex_keys], 'index') if draw_components: graph_renderer.node_renderer.data_source.add( self._get_connected_component_colors(), 'color') else: graph_renderer.node_renderer.data_source.add( self._get_random_colors(), 'color') graph_renderer.node_renderer.glyph = Circle(size=circle_size, fill_color='color') graph_renderer.edge_renderer.data_source.data = self._get_edge_indexes( ) self.randomize() graph_renderer.layout_provider = StaticLayoutProvider( graph_layout=self.pos) self.plot.renderers.append(graph_renderer)
def animate_update( ): #this function animates the graph by continually increasing the time point being looked at day = time_slider.value if day <= 365: new_dict = [ Sb[day] / 2.3, Eb[day], Ia_ukb[day], Ia_kb[day], Is_nhb[day], Is_hb[day], Rb[day] / 2.3, Db[day] ] new_bar = [ Sb[day] / 1000, Eb[day] / 1000, Ia_ukb[day] / 1000, Ia_kb[day] / 1000, Is_nhb[day] / 1000, Is_hb[day] / 1000, Rb[day] / 1000, Db[day] / 1000 ] current_source.data = dict(sizes=new_dict) bar_source.data = dict(tall=new_bar, names=class_names, colors=Colorblind8) graph_renderer.node_renderer.data_source.add( current_source.data['sizes'], 'size') graph_renderer.node_renderer.glyph = Circle(size='size', fill_color='color') time_slider.value = day + 1 #progress to next time unit
def test_reset_triggers_range1d_callbacks(self, single_plot_page): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.add_tools(ResetTool(), ZoomInTool()) plot.x_range.callback = CustomJS(code=COUNT("xrcb")) plot.x_range.js_on_change('start', CustomJS(code=COUNT("xrstart"))) plot.x_range.js_on_change('end', CustomJS(code=COUNT("xrend"))) plot.y_range.callback = CustomJS(code=COUNT("yrcb")) plot.y_range.js_on_change('start', CustomJS(code=COUNT("yrstart"))) plot.y_range.js_on_change('end', CustomJS(code=COUNT("yrend"))) page = single_plot_page(plot) # Change the ranges using a zoom in tool button = page.get_toolbar_button('zoom-in') button.click() results = page.results assert results['xrcb'] == 1 assert results['xrstart'] == 1 assert results['xrend'] == 1 assert results['yrcb'] == 1 assert results['yrstart'] == 1 assert results['yrend'] == 1 # Click the reset tool and check the callback was called button = page.get_toolbar_button('reset') button.click() results = page.results assert results['xrcb'] == 2 assert results['xrstart'] == 2 assert results['xrend'] == 2 assert results['yrcb'] == 2 assert results['yrstart'] == 2 assert results['yrend'] == 2 assert page.has_no_console_errors()
def _initialize(self, figsize, **kwargs): map_options = GMapOptions(**kwargs) self.map = GMapPlot(x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, plot_width=figsize[0], plot_height=figsize[1]) self.map.api_key = self.key self.source = ColumnDataSource(dict( lat=[], lon=[], index=[], )) self.text = ColumnDataSource(dict( x=[], y=[], text=[], )) mapper = LinearColorMapper(palette=Magma[256]) circle = Circle(x="lon", y="lat", size=15, fill_color={ "field": "index", "transform": mapper }) text = Text(x="x", y="y", text="text") self.map.add_glyph(self.source, circle) self.map.add_glyph(self.text, text) self.map.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool()) session = push_session(curdoc()) curdoc().add_root(self.map) session.show()
def make_plot(): # Load data # selected_source = sorted(data_urls)[select.active] # data = pd.read_csv(data_urls[selected_source]) data = pd.read_csv(data_urls[select.value]) # Convert EPSG code p1 = Proj(init='epsg:4326') # this is the EPSG code of the original p2 = Proj(init='epsg:3857') # this is the EPSG code of the tiles transformed_coords = [ transform(p1, p2, x1, y1) for x1, y1 in zip(data['X'], data['Y']) ] data['X'], data['Y'] = (zip(*transformed_coords)) # Convert to coordinates src.data['X'] = data['X'] src.data['Y'] = data['Y'] # Set x-range and y-range of map x_range = Range1d(start=min(src.data['X']), end=max(src.data['X']), bounds=None) y_range = Range1d(start=min(src.data['Y']), end=max(src.data['Y']), bounds=None) # Plot figure p = figure(x_range=x_range, y_range=y_range) p.axis.visible = False circs = Circle(x='X', y='Y', size=10, line_color=None, fill_alpha=0.8, fill_color="blue") p.add_glyph(src, circs) p.add_tile(STAMEN_TONER) return p
def plot_geo(lat_list, lon_list, notebook=False): map_options = GMapOptions(lat=40.711724, lng=-74.011300, map_type="roadmap", zoom=11) plot = GMapPlot(x_range=Range1d(), y_range=Range1d(), map_options=map_options) plot.title.text = "Austin" # For GMaps to function, Google requires you obtain and enable an API key: # # https://developers.google.com/maps/documentation/javascript/get-api-key # # Replace the value below with your personal API key: plot.api_key = config.GOOGLE_API_KEY source = ColumnDataSource(data=dict( lat=lat_list, lon=lon_list, )) circle = Circle(x="lon", y="lat", size=15, fill_color="blue", fill_alpha=0.8, line_color=None) plot.add_glyph(source, circle) plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool()) if notebook: output_notebook() else: output_file("gmap_plot.html") show(plot)
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"])) plot = Plot(height=400, width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.add_tools( CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) slider = DateSlider(start=start, end=end, value=value, css_classes=["foo"], width=300, step=24 * 3600 * 1000) def cb(attr, old, new): source.data['val'] = [slider.value_as_date.isoformat()] slider.on_change('value', cb) doc.add_root(column(slider, plot))
def modify_doc(doc): source = ColumnDataSource(dict(x=[1, 2], y=[1, 1], val=["a", "b"])) plot = Plot(plot_height=400, plot_width=400, x_range=Range1d(0, 1), y_range=Range1d(0, 1), min_border=0) plot.add_glyph(source, Circle(x='x', y='y', size=20)) plot.add_tools( CustomAction(callback=CustomJS(args=dict(s=source), code=RECORD("data", "s.data")))) slider = RangeSlider(start=0, end=10, value=(1, 9), title="bar", css_classes=["foo"], width=300) def cb(attr, old, new): source.data['val'] = [old, new] slider.on_change('value', cb) doc.add_root(column(slider, plot))