【发布时间】:2019-11-13 07:16:21
【问题描述】:
我正在尝试创建交互式条形图。 我有以下数据框:
客户 ID|年龄 |性别|吸烟历史 |酒精历史
1 |18-24|中号 |不吸烟 |
2 |43-48| F |不吸烟 |
3 |37-42|中号 |未知 |
4 |18-24| F |未知 |未知
5 |43-48|中号 |以前的吸烟者 |
我想创建一个交互式图,我可以在其中选择列,它可以根据所选列的分组创建条形图,即通过基于组计算行数来创建总数。
它显示了两个下拉列表,可以在其中选择所需的列。
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"
有解决办法吗?
【问题讨论】:
标签: python pandas jupyter-notebook plotly ipywidgets