Skip to content

Instantly share code, notes, and snippets.

@kdodia
Last active August 29, 2015 14:05
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 kdodia/ffb89e1492a7a06fc894 to your computer and use it in GitHub Desktop.
Save kdodia/ffb89e1492a7a06fc894 to your computer and use it in GitHub Desktop.
Changing Categorical Axis
## Works in Bokeh 0.5.2
from __future__ import print_function
import time
import webbrowser
import requests
from requests.exceptions import ConnectionError
from bokeh.widgetobjects import Select, HBox, VBox
from bokeh.glyphs import Line, Rect
from bokeh.document import Document
from bokeh.session import Session
import bokeh.plotting as bkp
document = Document()
session = Session()
session.use_doc('test')
session.load_document(document)
factors = ['a','b','c']
plot = bkp.rect(x=factors, y=[1,2,3],
width=0.9, height=1, x_range=factors, fill_color="#3B8686")
def update_data():
plot.x_range.factors = ['a','b','c','d']
session.store_document(document)
print('updated')
def on_widget_change(obj, attr, old, new):
update_data()
def layout():
select = Select(title="Date:", value="World", options=['option1','option2'])
select.on_change('value', on_widget_change)
controls = HBox(children=[select])
layout = VBox(children=[controls, plot])
return layout
document.add(layout())
if __name__ == "__main__":
link = session.object_link(document._plotcontext)
print("Please visit %s to see the plots" % link)
session.store_document(document)
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