繁体   English   中英

在Jupyter笔记本中通过IPywidgets创建交互式图

[英]Create interactive plot by IPywidgets in Jupyter notebook

我正在尝试创建交互式条形图。 我有以下数据框:

客户ID | 年龄|性别|吸烟史|酒精史


1 | 18-24 | M | 非吸烟者| 每周少于21个单位

2 | 43-48 | F | 非吸烟者| 每周少于21个单位

3 | 37-42 | M | 未知 每周少于21个单位

4 | 18-24 | F | 未知 未知

5 | 43-48 | M | 以前的吸烟者| 每周少于21个单位

我想创建一个交互式图,在其中可以选择列,它可以基于所选列的分组依据创建条形图,即通过基于分组对行进行计数来计算总数。

它显示了两个下拉列表,可以在其中选择所需的列。

 from plotly.offline import iplot, init_notebook_mode
 import plotly.graph_objs as go
 init_notebook_mode()
 import plotly 


@interact
def bar_plot(x=list([['Age', 'Gender', 'Smoking history', 'Alcohol 
history']]), y=list(df[['Gender', 'Smoking history', 'Alcohol 
history']])):

df.iplot(kind='bar', x=x, y=y,  
         xTitle=x.title(), yTitle=y.title(),             
         title=f'{y.title()} vs {x.title()}')

但是它不会创建任何输出。 而是显示错误:

"C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\display.py:689: 

用户警告:

Consider using IPython.display.IFrame instead"

有解决的办法吗?

我相信您只需要在init_notebook_mode内添加connected = True: 密谋离线文档

init_notebook_mode(connected=True)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM