【问题标题】:ipywidgets: how to update plot with multiple series based on checkbox selectionipywidgets:如何根据复选框选择更新具有多个系列的绘图
【发布时间】:2019-10-06 00:09:54
【问题描述】:

我正在使用 Ipython 笔记本、pandas 库和散景绘图库,并且我有一个生成网格图的函数。我正在尝试设置一些复选框,每个复选框对应于其中一个图,然后仅使用选中了相应复选框的图更新网格图。似乎对 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)

【问题讨论】:

    标签: python pandas checkbox ipython bokeh


    【解决方案1】:

    这会显示复选框并在更改时调用 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})
    

    【讨论】:

    • 谢谢!作为后续,您对如何添加“全选/全部清除”复选框有任何建议。我猜我必须创建另一组复选框并将两者联系起来,但我无法弄清楚如何做到这一点。
    猜你喜欢
    • 2021-09-28
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    相关资源
    最近更新 更多