import random import pandas as pd import bokeh.plotting as bk fruits = ["orange", "plum", "lime"] data = [(random.choice(fruits), random.randint(0,100), random.randint(0,100)) for i in range(16)] dframe = pd.DataFrame(data, columns=["fruit", "x", "y"]) dframe source = bk.ColumnDataSource(dframe) bk.output_notebook() p = bk.figure(title="Fruity", tools="pan,wheel_zoom,box_zoom,reset,resize,hover") p.circle(x='x', y='y', color='fruit', size=8, source=source) by_fruit = dframe.groupby('fruit') def update(fruit): grouped = by_fruit.get_group(fruit) # Going through and re-assigning to every column of source.data works, # but it gets verbose and repetitive as the number of source columns grows. # Is there a more elegant way to do this? source.data['x'] = grouped['x'] source.data['y'] = grouped['y'] source.data['fruit'] = grouped['fruit'] source.push_notebook() bk.show(p) from IPython.html.widgets import interact interact(update, fruit=fruits)