微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

python – ipywidgets:如何根据复选框选择更新多个系列的绘图

我正在使用Ipython笔记本,pandas库和散景图库,我有一个生成网格图的功能.我正在尝试设置一些复选框,每个复选框对应于其中一个图,然后仅使用选中了相应复选框的图更新网格图.似乎没有太多支持ipywidgets libray.这是我到目前为止的尝试;我不知道如何将我创建的复选框传递给我的函数来更新我的网格图,所以任何帮助都将非常感激.谢谢.

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, interactive
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.iteritems()]

interact(updatePlot, **{c.description: c.value for c in chk})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐