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

标签 python pandas checkbox ipython bokeh

我正在使用 Ipython 笔记本、pandas 库和 Bokeh 绘图库,并且我有一个生成网格图的函数。我正在尝试设置一些复选框,每个复选框对应于其中一个图,然后仅使用选中了相应复选框的图更新网格图。 ipywidgets 库似乎没有太多支持。到目前为止,这是我的尝试;我不确定如何将我创建的复选框传递给我的函数来更新我的网格图,所以任何帮助将不胜感激。谢谢。

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)

最佳答案

这会显示复选框并在它们发生变化时调用 updatePlot 函数:

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})

关于python - ipywidgets : how to update plot with multiple series based on checkbox selection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33371083/

相关文章:

python - 如何在特定条件下仅获取数据帧的第二个索引

python - 将非零值替换为 1

javascript - 仅在 Blade 模板中使用 JQuery 检查每行的复选框

javascript - 关于检查复选框类状态的问题

php - 在 Python 中使用 POST 将数据发送到 PHP

python - 如何使用照片模块中的 pick_asset?

python - pandas 中 groupby 统计数据中的 NaN 值

python - conda env 在幕后做了什么?

python - 如何检查 AWS S3 存储桶是否存在?

c# - OnCheckedChanged 事件未触发