0

I am trying to create an interactive bar plot. I have the following dataframe:

CustID| Age |Gender|Smoking_history |Alcohol_history


1 |18-24| M | Non-smoker | <21 units per week

2 |43-48| F | Non-smoker | <21 units per week

3 |37-42| M | Unknown | <21 units per week

4 |18-24| F | Unknown | Unknown

5 |43-48| M | Previous smoker | <21 units per week

I want to create an interactive plot where I can select columns and it can create a bar plot based on group by of the selected columns, i.e. total numbers by counting rows based on the group.

It shows two drop-down lists where the desired columns can be selected.

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

But it does not create any output. Instead it shows the error:

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

UserWarning:

Consider using IPython.display.IFrame instead"

Any idea to resolve it?

BPDESILVA
  • 2,040
  • 5
  • 15
  • 35

1 Answers1

0

I believe you just need to add connected=True inside of init_notebook_mode: plotly offline docs

init_notebook_mode(connected=True)
iampotential
  • 121
  • 9
  • No, it does not work. It shows the same "Consider using IPython.display.IFrame instead" error. – studentcoder Jul 03 '19 at 12:33
  • https://stackoverflow.com/questions/17619964/iframe-not-rendering-in-ipython-notebook – iampotential Jul 03 '19 at 13:58
  • It isnt an error. It is telling you that a suggestion to use ipython which will allow you to display your plot which is located at "C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\display.py:689" as an iframe inside of the notebook instead of a seperate file. Have you tried pasting that file into the browser as that seems to be where the file actually lives, but to put it inside the notebook you can use https://ipywidgets.readthedocs.io/en/stable/examples/Output%20Widget.html For example ive used from ipywidgets import VBox, HBox locally and it works – iampotential Jul 03 '19 at 14:05
  • Thanks , but it is not like that. Do not know what is the issue here. – studentcoder Jul 03 '19 at 14:07
  • If I use API key to access ploty, it creates the plot over there and provides link. But it is not creating locally. – studentcoder Jul 03 '19 at 14:09
  • And you imported the IPython display module as well? Its strange because it works on my end – iampotential Jul 03 '19 at 14:51
  • Yes. I imported IPython. But still shows: C:\ProgramData\Anaconda3\lib\site-packages\IPython\core\display.py:689: UserWarning: Consider using IPython.display.IFrame instead – studentcoder Jul 03 '19 at 15:20