import numpy as np from bokeh.plotting import output_notebook import pandas as pd output_notebook() from bokeh.plotting import line, show x = np.linspace(0, 4*np.pi, 20) y = np.sin(x) line(x,y, color="#0000FF", tools=[]) show() from bokeh.plotting import line import numpy as np x = np.linspace(0, 4*np.pi, 20) y = np.sin(x) line(x,y, color="#0000FF", tools=[], plot_width=400, plot_height=400) show() from bokeh.plotting import rect rect([10,20,30], [10,20,30], width=2, height=5, plot_width=400, plot_height=400, tools=[]) show() from bokeh.plotting import annular_wedge, hold, figure, show figure() #create a new figure hold(False) annular_wedge( [10,20,30], [30,25,10], 10, 20, 0.6, 4.1, inner_radius_units="screen", outer_radius_units = "screen", color="#8888ee", tools=[]) hold(True) rect([10,20,30], [10,20,30], width=2, height=5, plot_width=400, plot_height=400, tools=[]) show() hold(False) x = np.linspace(0, 4*np.pi, 20) y = np.sin(x) #use a scatter because select doesn't work on lines line(x,y, color="#0000FF", tools="pan, zoom, resize, select, save") show() from IPython.display import Image Image(filename='bokeh_objects.png') from numpy import pi, arange, sin, cos import numpy as np import os.path from bokeh.objects import (Plot, DataRange1d, LinearAxis, ObjectArrayDataSource, ColumnDataSource, Glyph, GridPlot, PanTool, ZoomTool) from bokeh.glyphs import Line, Rect from bokeh import session x = np.linspace(-2*pi, 2*pi, 100) y = sin(x) z = cos(x) widths = np.ones_like(x) * 0.02 heights = np.ones_like(x) * 0.2 #I'm putting all of this into a function so that we don't pollute the global namespace def simple_line_object(): from bokeh.plotting import curplot source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths, heights=heights)) xdr = DataRange1d(sources=[source.columns("x")]) ydr = DataRange1d(sources=[source.columns("y")]) line_glyph = Line(x="x", y="y", line_color="blue") renderer = Glyph(data_source = source, xdata_range = xdr, ydata_range = ydr, glyph = line_glyph) plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=50, height=300, width=300) xaxis = LinearAxis(plot=plot, dimension=0, location="bottom") yaxis = LinearAxis(plot=plot, dimension=1, location="left") pantool = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"]) zoomtool = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height")) plot.renderers.append(renderer) plot.tools = [pantool, zoomtool] sess = curplot()._session sess.add(plot, renderer, xaxis, yaxis, source, xdr, ydr, pantool, zoomtool) sess.plotcontext.children.append(plot) simple_line_object() show() from bokeh.glyphs import Wedge, Rect def simple_linked(): from bokeh.plotting import curplot source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths, heights=heights)) xdr = DataRange1d(sources=[source.columns("x")]) ydr = DataRange1d(sources=[source.columns("y")]) line_glyph = Line(x="x", y="y", line_color="blue") #FIXME, I can't seem to get other glyph styles to work rect_glyph = Rect(x="x", y="y", height=.5, width=.05, angle=30) wedge_glyph = Wedge(x="x", y="y", radius=np.pi/4, start_angle= np.pi/6, end_angle=np.pi/2, direction="clock", color="red") renderer = Glyph(data_source = source, xdata_range = xdr, ydata_range = ydr, glyph = line_glyph) plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=50, height=300, width=300) plot.renderers.append(renderer) renderer2 = Glyph(data_source = source, xdata_range = xdr, ydata_range = ydr, glyph = line_glyph) plot2 = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=50, height=300, width=300) pantool2 = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"]) zoomtool2 = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height")) plot2.renderers.append(renderer2) plot2.tools = [pantool2, zoomtool2] sess = curplot()._session sess.add(plot, renderer, source, xdr, ydr) sess.plotcontext.children.append(plot) show() sess.add(plot2, renderer2, pantool2, zoomtool2) sess.plotcontext.children.append(plot2) simple_linked() show() def line_advanced(): from bokeh.plotting import curplot source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths, heights=heights)) xdr = DataRange1d(sources=[source.columns("x")]) xdr2 = DataRange1d(sources=[source.columns("x")]) ydr = DataRange1d(sources=[source.columns("y")]) ydr2 = DataRange1d(sources=[source.columns("y")]) line_glyph = Line(x="x", y="y", line_color="blue") wedge_glyph = Wedge(x="x", y="y", radius=np.pi/14, start_angle= 3*np.pi/6, end_angle=4*np.pi/4, direction="clock") renderer = Glyph(data_source = source, xdata_range = xdr, ydata_range = ydr, glyph = line_glyph) pantool = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"]) zoomtool = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height")) plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=50, height=400, width=400) plot.tools = [pantool, zoomtool] plot.renderers.append(renderer) #notice that these two have a different y data range renderer2 = Glyph(data_source = source, xdata_range = xdr, ydata_range = ydr2, glyph = line_glyph) plot2 = Plot(x_range=xdr, y_range=ydr2, data_sources=[source], border=50, height=400, width=400) plot2.renderers.append(renderer2) #notice that these two have a differen y data range renderer3 = Glyph(data_source = source, xdata_range = xdr2, ydata_range = ydr, glyph = line_glyph) plot3 = Plot(x_range=xdr2, y_range=ydr, data_sources=[source], border=50, height=400, width=400) plot3.renderers.append(renderer3) #this is a dummy plot with no renderers plot4 = Plot(x_range=xdr2, y_range=ydr, data_sources=[source], border=50, height=400, width=400) sess = curplot()._session sess.add(plot, renderer, source, xdr, ydr, pantool, zoomtool) sess.add(plot2, renderer2, ydr2, xdr2, renderer3, plot3, plot4) grid = GridPlot(children=[[plot, plot2], [plot3, plot4 ]], name="linked_advanced") sess.add(grid) sess.plotcontext.children.append(grid) line_advanced() show() from bokeh.plotting import hold, line hold(False) x = np.linspace(0, 4*np.pi, 20) y = np.sin(x) hold(True) line_plot = line(x,y, color="#0000FF", tools="pan, zoom, preview, resize, select, embed, save") line_snippet = line_plot.inject_snippet() print line_snippet hold(False) import webbrowser import os #ok let's create an html page with that snippet open("foo.html","w").write("""