In [ ]:
from numpy import pi, arange, sin, cos
import numpy as np
In [ ]:
from bokeh import load_notebook
from bokeh.document import Document
from bokeh.glyphs import Circle
from bokeh.objects import (
Plot, DataRange1d, LinearAxis, Grid, ColumnDataSource, Glyph, PanTool, WheelZoomTool
)
In [ ]:
x = arange(-2*pi, 2*pi, 0.1)
y = sin(x)
width = np.ones_like(x) * 0.02
height = np.ones_like(x) * 0.2
In [ ]:
source = ColumnDataSource(data=dict(x=x, y=y,width=width, height=height))
xdr = DataRange1d(sources=[source.columns("x")])
ydr = DataRange1d(sources=[source.columns("y")])
In [ ]:
circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black")
In [ ]:
glyph_renderer = Glyph(
data_source = source,
xdata_range = xdr,
ydata_range = ydr,
glyph = circle,
)
In [ ]:
pantool = PanTool(dimensions=["width", "height"])
zoomtool = WheelZoomTool(dimensions=["width", "height"])
In [ ]:
plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], min_border=80)
In [ ]:
xaxis = LinearAxis(plot=plot, dimension=0)
yaxis = LinearAxis(plot=plot, dimension=1)
xgrid = Grid(plot=plot, dimension=0, axis=xaxis)
ygrid = Grid(plot=plot, dimension=1, axis=yaxis)
In [ ]:
plot.renderers.append(glyph_renderer)
plot.tools = [pantool,zoomtool]
In [ ]:
load_notebook(force=True)
In [ ]:
import IPython.core.displaypub as displaypub
from bokeh.embed import notebook_div
displaypub.publish_display_data('bokeh', {'text/html': notebook_div(plot)})
In [ ]: