Skip to content

Instantly share code, notes, and snippets.

@samchrisinger
Created July 29, 2014 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samchrisinger/17153672d721dea8bd13 to your computer and use it in GitHub Desktop.
Save samchrisinger/17153672d721dea8bd13 to your computer and use it in GitHub Desktop.
simple bokeh hist
from __future__ import print_function
import uuid
import time
from datetime import datetime
fts = datetime.fromtimestamp
from webbrowser import open_new_tab
from random import randint
from requests.exceptions import ConnectionError
from bokeh.document import Document
from bokeh.session import Session
from bokeh.objects import DataRange1d, ColumnDataSource, Plot, Glyph
from bokeh.glyphs import Quad
document = Document()
session = Session(load_from_config=False)
docname = str(uuid.uuid4())
session.use_doc(docname)
session.load_document(document)
data = {
'l': range(0,1000),
'r': range(1,1001),
'b': [0]*1000,
'y': [randint(0,1000) for i in range(1000)]
}
cols = ['l', 'r', 'b', 'y']
source = ColumnDataSource(
data=data,
column_names=cols
)
xdr = DataRange1d(sources=[source.columns(c) for c in ['l','r']])
ydr = DataRange1d(sources=[source.columns('y')])
quad = Quad(left='l',
right='r',
bottom='b',
top='y',
fill_color='red')
quad_renderer = Glyph(data_source=source,
xdata_range=xdr,
ydata_range=ydr,
glyph=quad)
plot = Plot(data_sources=[source],
x_range=xdr,
y_range=ydr,
plot_height=200,
plot_width=1200)
plot.renderers.append(quad_renderer)
document.add(plot)
session.store_document(document)
if __name__ == "__main__":
link = session.object_link(document._plotcontext)
open_new_tab(link)
try:
while True:
session.load_document(document)
time.sleep(0.5)
except KeyboardInterrupt:
print()
except ConnectionError:
print("Connection to bokeh-server was terminated")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment