Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ipywidgets: how to update plot with multiple series based on checkbox selection

I am using the Ipython notebook, pandas library, and the bokeh plotting library and I have a function that generates a gridplot. I am trying to set up some checkboxes, with each checkbox corresponding to one of those plots and then update the gridplot with only the plots that have their corresponding checkboxes selected. There does not seem to be much support for the ipywidgets libray. This is my attempt so far; I am not sure how to pass the checkboxes I created to my function to update my gridplot though, so any help will be much appreciated. Thanks.

attributes = df.columns.tolist()
from ipywidgets import Checkbox, interact
from IPython.display import display

chk = [Checkbox(description=attributes[i]) for i in range(len(attributes))]
#this displays the checkboxes I created correctly
display(*chk)

#update plot takes in the names of the columns to be displayed and returns 
#a gridplot containing all corresponding plots
#not sure about the part below though
interact(updatePlot,args=chk)
like image 528
cavs Avatar asked Dec 11 '22 20:12

cavs


1 Answers

This displays the checkboxes and calls the updatePlot function as they're changed:

from ipywidgets import Checkbox, interact
from IPython.display import display

l = ["Dog", "Cat", "Mouse"]
chk = [Checkbox(description=a) for a in l]

def updatePlot(**kwargs):
    print([(k,v) for k, v in kwargs.items()])

interact(updatePlot, **{c.description: c.value for c in chk})
like image 111
Randy Avatar answered Dec 26 '22 20:12

Randy